Get declaring type

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.
 
J

Jon Skeet [C# MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top