I did not completely wrap my head around one aspect of Generics.
Say I have a general class:
public abstract SomeClass<T> where T : SomeInterface { public bool DoSomethingsWithT(T theItem) {
So, I assume that the versions inheriting this class are active, but I allow some of them to define their own.
Now when I get the object in the method, which, as I know, will be of type SomeClass<T> , but T can be any class that implements SomeInterface
public bool SomeMethod(object item) { var something = item as SomeClass; return something.IsActive; }
But this, of course, does not work, because there is no class named SomeClass , and I also can not make SomeClass<SomeInterface> , since even if another class is inherited from it, I can not distinguish it.
How is this usually done? If we create a class called SomeClass that inherits SomeClass<SomeInterface> in this class, we define the IsActive property.
I see the exact same problem. If I was going to create a collection of elements inheriting SomeClass<SomeInterface> .
source share