Is there any mini C# console application available to pursue Reflection ?
IronPython for playing with .NET
objects. Not C#
, but really straightforward reflection on all .NET
objects.
>>> import clr
>>> import System
>>> ip=System.Net.IPAddress(System.Array[System.Byte]([10,0,0,1]))
>>> ip
<System.Net.IPAddress object at 0x0000000000000034 [10.0.0.1]>
>>> dir(ip)
['Address', 'AddressFamily', 'Any', 'Broadcast', 'Equals', 'GetAddressBytes', 'G
etHashCode', 'GetType', 'HostToNetworkOrder', 'IPv6Any', 'IPv6Loopback', 'IPv6No
ne', 'IsIPv6LinkLocal', 'IsIPv6Multicast', 'IsIPv6SiteLocal', 'IsLoopback', 'Loo
pback', 'MemberwiseClone', 'NetworkToHostOrder', 'None', 'Parse', 'ReferenceEqua
ls', 'ScopeId', 'ToString', 'TryParse', '__class__', '__delattr__', '__doc__', '
__eq__', '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__red
uce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__']
>>> ip.Address
16777226L
>>>
Have you tried the Immediate Window in Visual Studio?
I suggest that you try the types in the System.Reflection namespace there. Play around with the Assembly, Field/MethodInfo, Activator and Type classes.
For learning about assemblies and IL look at the System.Reflection.Emit namespace. A good example to start with is the one for the TypeBuilder class.
I agree that the Reflector utility is a really nice utility to explorer .NET assemblies.
If you want to build your own reflection application to learn about how metadata is structured I would recommend you read Expert .NET 2.0 IL Assembler. It gives a nice run down of how metadata is structured in assemblies today.
The .NET framework already exposes some reflection tools to developers, as stated by user "weiqure" and I would recommend that you sample the System.Reflection
namespace to get started with reflection too.
Check out http://www.codeproject.com/KB/library/fasterflect_.aspx which makes reflection "easier" to play with.