I had recently created a function to make loading multiple classes, while benchmarking the loading time easier with a simple method. I would like to know how I can extend this to allow multiple parameters passed to the method itself, and multiple parameters to the T (The class you're loading)
Method:
public static T CreateInstanceOf<T>() where T : new()
{
var stopwatch = Stopwatch.StartNew();
var result = new T();
stopwatch.Stop();
Logger.Trace("Loaded " + result.GetType().Name + " [took " + stopwatch.ElapsedMilliseconds + "ms]");
return result;
}
Current Usage:
_myClass = Utilities.Utilities.CreateInstanceOf<MyClass>();
Now, lets say that the class 'MyClass' had a public constructor, with multiple parameters, something like this
public MyClass(string name, int age, bool eating)
How could I extend the functionality to allow myself to send parameters to the class I am loading's constructor?
I would also like to pass extra parameters to the method itself, to include in the Logger.Trace line, can this be done?
Many Thanks, Seriosk.