Invoking Generic Methods using Reflection

by Mwwhited 11. August 2009 10:08
Using reflection to create classes and invoke methods can be tricky. Worse still can when you try to invoke methods with generic arguments. This is a short and quick example static void Main(string[] args) { var flags = BindingFlags.Static | BindingFlags.NonPublic; var t = typeof(Program); var mi = t.GetMethod("Loopback", flags); var gargs = mi.GetGenericArguments(); var pargs = new object[] {"input value"}; var gargIn = pargs.Select(a =&g... [More]

Tags: , ,

Programming

WCF RESTful Service Description Model (XML)

by Mwwhited 7. June 2009 12:06
One of the problems with RESTful services is not having a description language to allow for easy enumeration of services. This extension method allows for service classes to be described in an XML format that is easy to understand. public static XElement GetWebGetServices(this object input) { return new XElement("services", from method in input.GetType().GetMethods() let webInvoke = method.GetCustomAttributes(typeof(Web... [More]

Tags: , ,

Programming

Reflective XML Serializer with Recursion Detection

by Mwwhited 7. June 2009 11:06
Not being able to serialize Anonymous Types with the build in XmlSerializer was kind of a bummer for me, so I created this set of extension methods. Another feature I added at recursion detection based on the .GetHasCode() to prevent recursive object graphs from causing stack overflows. It's ugly... but it works... I was going for a proof of concept so I'm happy for now. -Enjoy, Matt using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Lin... [More]

Tags: , , , ,

Programming

Next stop Oslo... and MGrammar

by Mwwhited 16. May 2009 10:05
Now that my project is complete for the Dare to Dream Different Challenge for Microsoft .Net Micro Framework, I am going to move on to another new technology. I started to play with Oslo a few weeks back and totally fell in love with MGrammar. Next stop... to use MGrammar with Reflection.Emit to build a simple .Net Compiler http://msdn.microsoft.com/en-us/library/dd129870.aspx

Tags: , ,

Programming

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen