[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Retrieving a collection of all instances of a certain type in the current AppDomain

skbergam

8/2/2008 2:33:00 AM

Does anyone know if there is a way to retrieve a collection of all
instances of a certain type in the current AppDomain? I want to have
a function on my utility class with the following signature:

public static IEnumerable<T> GetAllInstances()

Does anyone know if this is possible?

5 Answers

(Mattias Sjögren)

8/2/2008 7:10:00 AM

0


>Does anyone know if there is a way to retrieve a collection of all
>instances of a certain type in the current AppDomain?

There's no general way to do that. It can be done from a debugger, but
not from your code (unless you write the class type and keep track of
all instances yourself).


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.n... | http://www.dotneti...
Please reply only to the newsgroup.

skbergam

8/3/2008 5:21:00 PM

0

On Aug 2, 12:09 am, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
> >Does anyone know if there is a way to retrieve acollectionofall
> >instancesof acertaintypein thecurrentAppDomain?
>
> There's no general way to do that. It can be done from a debugger, but
> not from your code (unless you write the classtypeand keep track ofallinstancesyourself).
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.orghttp://www.msjogren.n...|http://www.dotneti...
> Please reply only to the newsgroup.

How does the debugger do it? Is there a debugger API?

(Mattias Sjögren)

8/5/2008 8:09:00 AM

0

>How does the debugger do it? Is there a debugger API?

You can do a lot of fun things with the SOS debugger extensions
(http://msdn.microsoft.com/en-us/library/bb1...) and its
DumpHeap command. But I don't know exactly how it does it (I can
guess, but I don't think it would be of any help).


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.n... | http://www.dotneti...
Please reply only to the newsgroup.

NEMO

1/20/2012 3:17:00 AM

0

On Jan 19, 9:47 pm, Topaz <mars1...@hotmail.com> wrote:

\\\\Y////
^
( )
I I
oI Io

"Gobble - gobble, gobble - gobble, lick - lick, slurp - slurp!"

"Gulp - gulp!"

"Yum - yum, yum - yum!"

China Blue Veins

1/20/2012 4:01:00 AM

0

In article <ef829a55-252a-4aea-b557-974cf5fc3650@l16g2000vbl.googlegroups.com>,
NEMO <brianlambsbigtoe@excite.com> wrote:

> On Jan 19, 9:47 pm, Topaz <mars1...@hotmail.com> wrote:
>
> \\\\Y////
> ^
> ( )
> I I
> oI Io
>
> "Gobble - gobble, gobble - gobble, lick - lick, slurp - slurp!"
>
> "Gulp - gulp!"
>
> "Yum - yum, yum - yum!"

You do know that Goebbels is dead?





Though I suppose that wouldn't matter to Topaz.

--
My name Indigo Montoya. | Yippee-kay-yay, eh.
You flamed my father. | I'm whoever you want me to be.
Prepare to be spanked. | Annoying Usenet one post at a time.
Stop posting that! | At least I can stay in character.