I have the following classes:
class MyObject { }
class MyObject2 { }
interface Parent<T>
{
void DoSomething(T myObj);
}
class Child1 : Parent<MyObject1>
{
public void DoSomething(MyObject1 myObj) { }
}
class Child2 : Parent<MyObject2>
{
public void DoSomething(MyObject2 myObj) { }
}
I want to create a factory method which return the parent but I get the following casting error
Cannot implicitly convert type 'Child1' to 'Parent'. An explicit conversion exists (are you missing a cast?)
static Parent<object> Factory()
{
return new Child1();
}
Is there any workaround for this?