CodeDom Reflection Generator

As a step to further promote correct writing of generators using CodeDom, I’ve created a utility that takes an entire assembly and creates typed methods that create every type in it, invoke every method, reference every member, etc..

Now wait a second and try and understand what I just wrote up there. Give up? That’s ok, I gave before you did. Let’s just take an example and it’ll all be clear:

Take the Chars indexer for System.String. To access it, I would have to write an awefully long and untyped piece of code:

System.CodeDom.CodeIndexerExpression expression =
new System.CodeDom.CodeIndexerExpression(new System.CodeDom.CodePropertyReferenceExpression(myStringObjectReference, "Chars"), positionExpression);

Using the reflected assembly, I could simply write:

System.CodeDom.CodeIndexerExpression expression = System.ReflectedString.Properties.ReferenceIndexerChars(myStringObjectReference, positionExpression);

Let’s look at the greater scale now. Again, take .NET 1.1’s String class as an example. After putting mscorlib through the tool, you will receive a class named ReflectedString in an assembly named [CodeDomReflection]mscorlib.dll that knows exactly how not only the String class works, but the whole of the mscorlib assembly and can strongly reference every single part of it. Also, a complete documentation xml file is included for Intellisense’s sake.


The version I’m placing online for download is a perliminary beta. I’ve tested it on the entire framework and it worked great, but things may always break. Please let me know if they do.
Here are the bits. To do some magic, just use DotNetZen.CodeDom.Reflect assembly [strong name key file] (Yes, you can sign your assembly with a strong name key file so you could use it from your own signed generators).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s