Lest I forget…

In the latest round of edits for Campy, I am trying to get System.Console.WriteLine() working on a GPU–a task easier said than done. The changes have taken quite a bit of time, since as noted in the previous blog post, Mono Cecil has some quirkiness (e.g., ElementType and GetElementType() do not return the same types; Resolve() of an Array type returns the element type, not an Array type, because the resolver uses GetElementType()Resolve() of a generic instance type returns the type definition with all type arguments thrown away). Mono Cecil has the virtual method Resolve() to turn a type/method reference into a type/method definition. But, MemberReference doesn’t have a Deresolve() method that turns a generic type/method definition into a type/method reference with specific types, e.g., convert List<T> into List<int>.

Mono Cecil defines a class hierarchy for types, e.g., MethodReference, TypeReference, GenericParameter, GenericInstanceType, etc. Many of these classes in the type hierarchy are sealed and not partial. Unfortunately, C# method parametric polymorphism is not a substitute for virtual methods. Since the class hierarchy cannot be altered with a Deresolve() virtual method, I have to code a function that takes MethodReference and computes type specific computations in a large if-then-else.

In order to make my life easier, I exported the class diagram for the Mono.Cecil MemberReference type hierarchy from Visual Studio (although I almost never visualize code, or code with pictures, this time it comes in handy). Note: to create the diagram, I opened the Mono.Cecil solution, then in the Solution Explorer, right click on “View -> View Class Diagram”, print to “Microsoft Print to PDF”, edit the PDF file in Inkscape, and export to an SVG file.

–Ken