How can i call a method from a static class passing a type of dynamic in generic.
Here is my static class:
public static class Log<T>
{
private readonly static ILog Logger = LogManager.GetLogger(typeof(T));
public static void LogInfo(string message)
{
Logger.Info(message);
}
}
I want to call LogInfo like this:
Log<myObject.GetType()>.LogInfo("Some String");
My question is about how to pass a type of myObject in Generic, because the type of this object is dynamic.
Why? Why don’t you just do this:
Note that this is not, Not, NOT thread safe. I wanted to communicate the idea.
Then:
can be replaced by
or you can even go one step further and add an overload that allows you to say
(just call
object.GetTypeinLogInfo).