This is My Generic Class:
public class MyClass<T>
{
public T MainModel { get; set; }
public Type GetType()
{
//here
}
}
Then I use it this form:
List<MySecondClass> Myinstance = new List<MySecondClass>();
MyClass<IEnumerable<MySecondClass>> mainInstance = new MyClass<IEnumerable<MySecondClass>> { MainModel = Myinstance };
So I need the GetType() Method returned typeof(MySecondClass) what is your suggestion?
Update
I must mention that always use the MyClass in just two form: First : I exactly coded in above and Second:
ThirdClass thirdone = new ThirdClass();
MyClass<ThirdClass> = new MyClass<ThirdClass>(){ MainModel = thirdone};
If
TisList<T>See it in action.
If
TisIEnumerable<T>Important notes
You really should think about what
MyClassis trying to do here. Why does it want to special-case forTbeing anIEnumerable<X>? Perhaps some constraints should be added onT? It’s not possible to answer these and other important questions without more concrete information, but you really should do so.Also, did you name the method
GetTypeby accident or on purpose? It’s really, really, really not a good idea to hideobject.GetTypelike that, so I would suggest you rename that method.