public class TestClass1
{
public void TestMethod1()
{
new Logger<TestClass1>().Log(LogType.Info, "FROM TESTCLASS1.TESTMETHOD1");
}
}
When instantiating Logger and passing in TestClass1 as generic T, there could be a problem if the developer types in some thing else as opposed to TestClass1. For example, following line of code could be an issue.
new Logger<Test123>().Log(LogType.Info, "FROM TESTCLASS1.TESTMETHOD1");
How can I write the following line of code that it would automatically infer TestClass1 and pass it?
new Logger<TestClass1>().Log(LogType.Info, "FROM TESTCLASS1.TESTMETHOD1");
I have tried the following 2 lines of code but no luck.
new Logger<this>().Log(LogType.Info, "FROM TESTCLASS1.TESTMETHOD1");
new Logger<this.GetType>().Log(LogType.Info, "FROM TESTCLASS1.TESTMETHOD1");
UPDATE
Through out my application, I could be passing in any class whats so ever such as TestClass1, MyClass123 etc. etc. so I may not be able to put any generic constraints.
Please help.
How about an extension method:
so you can