What strongly typed properties are you trying to get? If they are strongly typed because they are input types of common ones, then you cannot access them without supplying types in your foreach loop. If they are strongly typed but not related to the supplied types, can you transfer them to the IRelation class?
This will make more sense with the sample code - let's say your classes are something like:
public IRelation { public string RelationshipType { get; set; } } public IGenericRelation<TParent, TChild> : IRelation { public TParent Parent { get; set; } public TChild Child { get; set; } }
If your list contains one IGenericRelation<Foo, Bar> and one IGenericRelation<Fizz, Buzz> , you cannot list and return both without knowing what specific type you are looking for:
(Note that I also had to change the type of the Control relationship in foreach from your sample code, so the possible use makes sense.)
In principle, it may be useful to think that .NET generics are the same as templates with a C ++ template (I know that the implementation is different, but the effect is the same in this respect). Imagine that during compilation all your code is checked for the use of the IGenericRelation class, and specific, not general, classes are created by searching for the TParent and TChild keywords and replacing them with the requested type. Since the two classes created are just as separate as any other .NET classes, it makes no sense to query "all classes that started like this template", the best thing you can do is find a common base class or interface - in this case, IRelation.
Martin harris
source share