Reflection, Classes and the Lack of Binary Compatibility

  • Thread starter Thread starter Phill. W
  • Start date Start date
P

Phill. W

Does anyone happen to have a snippet of [VB 2003] code that,
for a given Type, produces a list of [all] the properties, methods,
constructors, and so on for that Class?

TIA,
Phill W.
 
Phill. W said:
Does anyone happen to have a snippet of [VB 2003] code that,
for a given Type, produces a list of [all] the properties, methods,
constructors, and so on for that Class?

I do not have such a snippet, but creatint such a snippet should not be that
hard when using the 'Type' class and its methods.
 
Phill,
Have you looked at the on-line help for System.Type? Specifically:

Type.GetMembers

http://msdn.microsoft.com/library/d.../html/frlrfsystemtypeclassgetmemberstopic.asp

If want specific "types" of members instead of all members, try:

Type.GetProperties
Type.GetFields
Type.GetEvents
Type.GetMethods
Type.GetConstructors
Type.GetNestedTypes


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Does anyone happen to have a snippet of [VB 2003] code that,
| for a given Type, produces a list of [all] the properties, methods,
| constructors, and so on for that Class?
|
| TIA,
| Phill W.
|
|
 
Herfried K. Wagner said:
Phill. W said:
Does anyone happen to have a snippet of [VB 2003] code that,
for a given Type, produces a list of [all] the properties, methods,
constructors, and so on for that Class?

I do not have such a snippet, but creatint such a snippet should not be that
hard when using the 'Type' class and its methods.

Herfried,

You're right; it's /not/ that bad - at least up to a point.
I've successfully iterated all my constructors, methods and properties
(using the fairly obvious GetConstructors, GetMethods, GetProperties),
but how do I pull out any Enum's my class might expose?

TIA,
Phill W.
 
Phill,
You would need to use Type.GetNestedTypes() to get any Enums (and other
types) that you may have nested inside another type.

FWIW: I rarely nest Enums inside of another type, rather I place them at
file scope either in with the primary type that uses them or in their own
file. Something like:

---x--- class1.vb ---x---
Public Enum Enum1
Value1
End Enum

Public Class Class1
...
End Class
---x---


---x--- Enum2.vb ---x---
Public Enum Enum2
Value1
End Enum
---x---

---x--- AnotherType.vb ---x---
Public Class AnotherType
...
End Class
---x---

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| | > > Does anyone happen to have a snippet of [VB 2003] code that,
| > > for a given Type, produces a list of [all] the properties, methods,
| > > constructors, and so on for that Class?
| >
| > I do not have such a snippet, but creatint such a snippet should not be
| that
| > hard when using the 'Type' class and its methods.
|
| Herfried,
|
| You're right; it's /not/ that bad - at least up to a point.
| I've successfully iterated all my constructors, methods and properties
| (using the fairly obvious GetConstructors, GetMethods, GetProperties),
| but how do I pull out any Enum's my class might expose?
|
| TIA,
| Phill W.
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top