So, I have the following structure:
public abstract class MyBase
{
public Type TargetType { get; protected set; }
}
public class A : MyBase
{
public A()
{
TargetType = GetType();//Wrong, I need B class type not C
}
}
public class B : A
{
public B() { }
}
public class C : B
{
public C() { }
}
Of course, I can receive my type in this way:
public class B : A
{
public B()
{
TargetType = typeof(B);
}
}
Actually, I have to write some code to make the example clearer:
Class1.cs
public static Dictionary<Type, Type> MyTypes = new Dictionary<Type, Type>()
{
{ typeof(B),typeof(BView) }
}
public Class1()
{
C itemC = new C();
Class2.Initialize(itemC);
}
Class2.cs
public static Initialize(MyBase myBase)
{
Type t;
Class1.MyTypes.TryGetValue(myBase.TargetType, out t);
//I need get BView but I get null because *myBase.TargetType* is C class type
}
Level structure:
- Level 0:(MyBase) - 1 object
- Level 1:(A) - 2 objects
- Level 2:(B) - 100 objects and more
- Level 3:(C) - 80 objects and more
I gave this case in brackets
I will be grateful for any help