SignatureResolver (unfinished)

While writing the ILVisualizer for dynamic method late 2005, I’d like to show the local variable information as well; so I started working on the managed signature parser, at least to parse LocalVarSig (Ecma-335 23.2.6). It was 2+ years ago, and never got to a finished state. Now perhaps I will never spend more time…

1

Name of Array Type

Two things related to array type name came to my mind while writing the previous post. Given an one-dimensional non-zero based double array x, x.GetType().ToString() returns “System.Double[*]”; we can use Type.GetType(“System.Double[*]”) to get hold of such type easily. To get an instance of such type, instead of calling Array.CreateInstance, we can find ConstructorInfo first, and…


Late-bound Array SetValue

The type “System.Array” provides us a set of API for the late-bound array operations, including array creation (Array.CreateInstance), read/write access to array element (Array.SetValue/Array.GetValue). They are convenient to use. Let me start with some code to create an one-dimensional integer array, and set the first 2 elements using early-bind assignment and Array.SetValue, respectively. To simplify…


Take Two: IL Visualizer

I was glad to hear many positive feedbacks about the DebuggerVisualizer for DynamicMethod; on the sad side, it shows our lack of good LCG debugging support (on which, Mike Stall is seeking your opinion). Recently along with the ILReader update, I made a few changes on the visualizer: Add support to show IL of RuntimeMethodInfo…

6

System.Reflection-based ILReader

Compared to what I posted previously here (or what was used in the DynamicMethod visualizer), this new version introduced the Visitor pattern. A do-nothing visitor ILInstructionVisitor is included; the users can focus on their domain-specific logic by simply inheriting from it and overriding few methods. public abstract class ILInstructionVisitor {    public virtual void VisitInlineBrTargetInstruction(InlineBrTargetInstruction inlineBrTargetInstruction)…

2

Member Order Returned by GetFields, GetMethods …

As John mentioned in his post, every Reflection user should keep this in mind: our code should not count on the member order returned by GetFields, GetMethods and other similar GetXXXs calls. Given two fields (F1, F2) in one type, I think the compiler is free to emit F1 before F2, or vice versa. Also…

9

My Attribute Disappears

The GetCustomAttributes scenario (ICustomAttributeProvider.GetCustomAttributes or Attribute.GetCustomAttributes, referred to as GetCA in this post) involves 3 pieces: a custom attribute type an entity which is decorated with the custom attribute a code snippet calling GetCA on the decorated entity. These pieces could be residing together in one assembly; or separately in 3 different assemblies. The following…

3

Type.FullName returns null when …

Type.FullName returns null when the type is not generic type definition but contains generic paramters. The rational behind this design is to ensure Type.FullName (if not null) can uniquely identify a type in an assembly; or given the string returned by Type.FullName, Type.GetType(string typeName) can return the original type back. It is hard to keep…

2

Use IronPython to Experiment .NET Libraries

When working on .NET projects, we often need to find the right API or the proper parameters to pass in to a particular method. Usually we search MSDN or turn to other search engines to solve such issue. Some people, however, prefer first-hand experience over search; they perfer experimenting or playing with a small piece…

2

Activator.CreateInstance and beyond

Q: Assume we have 2000 unknown types; (however) we know each type has a constructor with integer as its’ only parameter type. How to create objects 10000 times for each type (and make such late-new fast)? Activator.CreateInstance comes to my fingers first. It is just so convenient to use: calling Activator.CreateInstance(type, new object[] {100}) in…

12