C# Reflecion - Is it possible?

  • Thread starter Thread starter David Krmpotic
  • Start date Start date
D

David Krmpotic

Hello,

I want to find all the objects of some type that are currently in memory.

So it is somehow reverse from GetType().

I want to do this:

foreach(MyObject o in AllTheObjectsOfGivenType(typeof(MyObject))
{
...
}


Any suggestions please? Thank you!

David
 
Smalltalk supports "obj allInstances" and is one of the few that do.
It's normally considered but practice to to rely on the environment for
this, as it may be hard return "all" objects in a multthread, GC'd
environment, and having the system always ready return all instances may
incur constant overhead that you wouldn't want to impose on all programs.
You'll probably need to keep your own collection of objects of the types you
want to track and you may want to use the WeakReference class so that your
collection doesn't keep objects alive that are meant to be reclaimed,
depending on how you're tracking the objects.

m
 
Thank you Mike,

Actually I wanted to use this feature just out of convenience. Now I'll
register all the objects manually. I was making a simple Testing framework.
All the classes that derive from the TestingBase now have to register
themselves with TestingManager which runs the tests on all of them on
request. That works fine now. Thank you!


David Krmpotic
http://www.david13.com
 
Thank you - yes I've heard of it, but I didn't use it yet.
I wanted to make a simple one of my own. It took me like a few hours (hehe
it shouldn't even take that).

But now I am going to check NUnit out to get new ideas :)
 
Back
Top