Getting a list of Instantiated Types

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have three Types (in different assemblies) A (which is abstract), B and C.
B inherits A and C inherits B. My host Windows Application creates an
instance of C.

I would like to be able to look at this EXE and be able to tell that only
object C was directly instantiated. Currently I am using the AppDomain
GetAssemblies() method but this gives me Assemblies A, B and C.

So really this all boils down to how can I tell or can a class tell if it
was directly instantiated or if it was created by inheritance.

Help would be very much appreciated.

Thanks
 
James Wren said:
Hi,

I have three Types (in different assemblies) A (which is abstract), B and
C.
B inherits A and C inherits B. My host Windows Application creates an
instance of C.

I would like to be able to look at this EXE and be able to tell that only
object C was directly instantiated. Currently I am using the AppDomain
GetAssemblies() method but this gives me Assemblies A, B and C.

So really this all boils down to how can I tell or can a class tell if it
was directly instantiated or if it was created by inheritance.

Call System.Object.GetType()

I think in .Net the object becomes alive as the most derived type before any
constructors are called (which is different from native C++, for example).

If I'm wrong about that, you can still build a collection of instances and
iterate through calling GetType() later after the constructors finish
running.
 
Many thanks, you are absolutley right GetType() returns the most derived type
and has sorted my problem.

Thanks
 
Back
Top