Intellisense at runtime

  • Thread starter Thread starter Hananiel
  • Start date Start date
H

Hananiel

How can you see an object's members at run-time programmatically. I want to
write code that looks like :
MyObject myObject;
foreach ( object member in myObject)
{
DoSomeThingWith(member);
}

Thanks,
Hananiel
 
You would use reflection to do this.

Something like:

using System.Reflection;

Type t = typeof(MyObject);
MemberInfo[] members = t.GetMembers();
foreach(MemberInfo mi in members){
//Do what you want here
}

GetMembers gets all the members of the given type. There
is also GetProperties, GetMethods, GetInterfaces, etc.

Also, you can pick out a member by name instead of
retrieving an array: t.GetMethod("CookSalsburySteak");

HTH,
Charlie
 
Thank you. Just what i needed.
-Hananiel
Charlie Williams said:
You would use reflection to do this.

Something like:

using System.Reflection;

Type t = typeof(MyObject);
MemberInfo[] members = t.GetMembers();
foreach(MemberInfo mi in members){
//Do what you want here
}

GetMembers gets all the members of the given type. There
is also GetProperties, GetMethods, GetInterfaces, etc.

Also, you can pick out a member by name instead of
retrieving an array: t.GetMethod("CookSalsburySteak");

HTH,
Charlie
-----Original Message-----
How can you see an object's members at run-time programmatically. I want to
write code that looks like :
MyObject myObject;
foreach ( object member in myObject)
{
DoSomeThingWith(member);
}

Thanks,
Hananiel


.
 
Back
Top