DaveWentzel.com            All Things Data



Reflection is something new to .NET...we didn't have it in COM.  It is very important to PS. 
What is Reflection?
Allows you to look inside an assembly and find out its characteristics.  It allows you to explore the hierarchy of assemblies, modules, classes, and members. 
Reflection uses System.Reflection and System.Type
You can find the members of any .NET class at runtime using get-member.  First off, you need to know get-process  which lists details for all running processes on your machine.  For example: 
Next we can use the following to get a list of all members of any .NET class at runtime by combining get-process with get-member
The following example uses the static property Now of a .NET class and assigns the value to a variable: 
Another example...I know a piece of code is returning a datetime type.  What can I do with it?  Just run get-member like the following:
This is basically a full-list of members for that class. 
Note some interesting methods such as .Equals and .ToString.  Need a more abbreviated list.  Just use some additional parameters to filter the list:
PS C:\Documents and Settings\dwentzel> [System.DateTime]|get-member -membertype

just display the available methods
PS C:\Documents and Settings\dwentzel> [System.DateTime]|get-member -membertype

just display the available properties
PS C:\Documents and Settings\dwentzel> [System.DateTime]|get-member -static
just display the statics

Add new comment