Home All Groups Group Topic Archive Search About

Getting a list of Instantiated Types

Author
5 Mar 2007 5:46 PM
James Wren
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

Author
5 Mar 2007 7:33 PM
Ben Voigt
Show quote
"James Wren" <JamesW***@discussions.microsoft.com> wrote in message
news:03A501E9-9786-44E6-AA6B-7D07AF02D4EF@microsoft.com...
> 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.

Show quote
>
> Help would be very much appreciated.
>
> Thanks
Author
6 Mar 2007 3:16 PM
James Wren
Many thanks, you are absolutley right GetType() returns the most derived type
and has sorted my problem.

Thanks


Show quote
"Ben Voigt" wrote:

>
> "James Wren" <JamesW***@discussions.microsoft.com> wrote in message
> news:03A501E9-9786-44E6-AA6B-7D07AF02D4EF@microsoft.com...
> > 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.
>
> >
> > Help would be very much appreciated.
> >
> > Thanks
>
>
>

AddThis Social Bookmark Button