I don’t know how to explain this exactly, but I’ll have a go anyway.
I’ve got a base User Control that requires a generic type to be passed through.
public abstract class BaseControl<T> : UserControl where T : BaseClass, new()
{
}
The purpose of the Base Control is to edit properties of children of BaseClass.
Then I have a couple of controls similar to the following
public partial class MyControl : BaseControl<MyClass>
{
}
“MyClass” is inheriting BaseClass.
So lets say I have MyControl and others similar to it used in a page.
Can I do something like the following to get all controls that are inheriting from BaseClass?
foreach(BaseControl<T> c in this.Controls)
{
//do stuff
}
Not terribly easily. It would be simpler if you had a non-generic
BaseControlwhichBaseControl<T>inherited from:then
You could put any members which didn’t depend on
Tin the non-generic class, too.Aside from that, you could examine each control’s type hierarchy and see whether any of them use either the generic or non-generic form of
BaseControl<T>, but it would be somewhat messier than this.