I have two classes like these.
public class MyClass
{
protected readonly int SomeVariable;
public MyClass(){}
public MyClass(int someVariable)
{
SomeVariable = someVariable;
}
}
public class MyClass2 : MyClass {}
Is there a way to create an instance of the class using Activator.CreateInstance? I wrote something like this:
public class ActivatorTest<TViewModel>
where TViewModel : MyClass
{
public void Run()
{
var viewModel = Activator.CreateInstance(typeof(TViewModel), new Object[] {2}) as TViewModel;
}
}
new ActivatorTest<MyClass2>().Run();
But I had an exception Constructor on type 'MyClass2' not found.
Any ideas?