Reflecting on an executing assembly

  • Thread starter Thread starter Tim Greenwood
  • Start date Start date
T

Tim Greenwood

I was wondering how to go about looking at an executing assembly and getting
a list of not all types but all instantiated types and references to those
objects. Something similar to what the propertygrid in Visual Studio is
doing....I need to provide property grid like functionality for one of our
internal apps.

The snippet below shows what I've done which gives me a list of all the
types in the assembly...great. Now how do I conjure up a reference to an
instance of one of these types? I don't want to create a new one, I want to
find the ones already running so the users can see the runtime properties of
their UI.
---------------------------------------------------------------------------------
private Type[] tArray;
Module[] moduleArray;
Module modCurrent;

public propgrid()
{
InitializeComponent();
}

private void propgrid_Load(object sender, EventArgs e)
{
moduleArray = Assembly.GetExecutingAssembly().GetModules(false);
this.cboModules.DataSource = moduleArray;
}

private void cboModules_SelectedIndexChanged(object sender,
EventArgs e)
{
if (!cboModules.Focused) return;
if (cboModules.SelectedIndex == null) return;
modCurrent = moduleArray[cboModules.SelectedIndex];
tArray = modCurrent.FindTypes(Module.FilterTypeName, "*");
cboObjects.DataSource = tArray;
---------------------------------------------------------------------------------
 
I was wondering how to go about looking at an executing assembly and getting
a list of not all types but all instantiated types and references to those
objects.

No, you can't do that, at least not without using a debugging/profiling
API.
 
So then how does Visual Studio do it? Obviously the forms designer property
grid is showing us the properties of the objects it has instantiated....is
it reflecting? Or is it keeping an internal list of what it has created?
 
So then how does Visual Studio do it? Obviously the forms designer property
grid is showing us the properties of the objects it has instantiated....is
it reflecting? Or is it keeping an internal list of what it has created?

Given that it's got to create the code to *recreate* the objects it's
created, yes, it keeps a list of things it's designing.
 
Back
Top