I want to be able to derive from a class internally, but disallow class in other assemblies to derive from the class
- by Rokke
Hej
I have the following setup:
Assembly 1
public abstract class XX<T> : XX where T: YY { }
public abstract class XX {}
Assembly 2
public class ZZ : YY {}
public class ZZFriend : XX<ZZ> {}
I use this feature in reflection when in YY:
public class YY {
public Type FindFriend {
return GetType().Assembly.GetTypes().FirstOrDefault(
t => t.BaseType != null &&
t.BaseType.IsGenericType &&
typeof(XX).IsAssignableFrom(t) &&
t.BaseType.GetGenericArguments().FirstOrDefault() == GetType());
}
}
I would like do disallow inheritance of the non generic class XX like:
public class ZZFriend: XX {}
Alternatively, I need a method like (that can be used in the reflection in YY.FindFrind()):
public Type F(Type t) {
return GetTypeThatIsGeneric(XX, Type genericTypeParameter);
}
That can be used in YY as:
Typeof(XX<ZZ) == F(typeof(GetType())
Hope that makes sense...
Thanks in advance
Søren Rokkedal