Get declaring type

  • Thread starter Thread starter Maarten Terlingen
  • Start date Start date
M

Maarten Terlingen

Sample:

ClassA: ClassB
ClassB: ClassC
ClassA x = new Class C

I want to know the declaring type of C.
x.GetType() returns C
x.GetType().BaseType returns B
x.GetType().BaseType.BaseType returns A, but I don't know the depth in my
program. So I don't know how many times I have to user
BaseType.BaseType.Ba.... etc.
x.GetType().DeclaringType does not exist. Don't know why.

How can I retrieve the declaring type of C?? So I need to now that the
declaring type of C is A.
 
Maarten Terlingen said:
Sample:

ClassA: ClassB
ClassB: ClassC
ClassA x = new Class C

I want to know the declaring type of C.
x.GetType() returns C
x.GetType().BaseType returns B
x.GetType().BaseType.BaseType returns A, but I don't know the depth in my
program. So I don't know how many times I have to user
BaseType.BaseType.Ba.... etc.
x.GetType().DeclaringType does not exist. Don't know why.

How can I retrieve the declaring type of C?? So I need to now that the
declaring type of C is A.

What exactly do you mean by "the declaring type of C"? Do you
*actually* mean the declared type of the variable x? If not, could you
clarify exactly what you do mean?
 
Back
Top