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…

0

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…

0

Set Value on Array: Performance Test

// // Please refer to http://blogs.msdn.com/haibo_luo “Late-bound array operations” post // // To compile this file, you need download Vance’s CodeTimers class // @ http://blogs.msdn.com/vancem/archive/2006/09/21/765648.aspx // // THIS CODE IS PROVIDED “AS IS”, WITH NO WARRANTIES INTENDED OR IMPLIED. USE AT YOUR OWN RISK // using System; using System.Collections.Generic; using System.Text; using PerformanceMeasurement; using System.Reflection.Emit;…

1

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

Turn MethodInfo to DynamicMethod

I do not know why anyone ever need this 🙂 but few readers did ask me similar questions before. Solving this problem also demonstrates one more ILReader usage. To build a DynamicMethod, we can choose either DynamicILGenerator or DynamicILInfo. My first impression of using DynamicILGenerator to emit code is slow: you need make calls to…

2

Try ILReader

# # Sample code to demonstrate how to use ILReader # By Haibo Luo @ http://blogs.msdn.com/haibo_luo # # THIS CODE IS PROVIDED “AS IS”, WITH NO WARRANTIES INTENDED OR IMPLIED. USE AT YOUR OWN RISK # import clr, sys, System try: clr.AddReference(r’ClrTest.Reflection.ILReader.dll’) except: print ‘\nFail to add reference of ILReader. One simple fix is to…

2

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

Always Peverify IL Code of your Dynamic Method

Current dynamic method implementation does not have built-in support to pre-check whether the dynamic method code is verifiable. With bad IL sequence, very often you will get “System.InvalidProgramException: Common Language Runtime detected an invalid program” when it gets executed. See the code example below, where C1, C2 are 2 simple reference types. Btw I understand…

0

Shift Away from CLR Reflection Area

After 2-year Reflection test ownership and 1-year babysitting for Reflection.Emit and DynamicMethod areas, I am gradually away from these CLR feature areas, and will be more focusing on IronPython (and maybe others later). Before completely leaving them behind, first of all, I want to apologize to you if you sent me emails about this blog before and I did not reply. I…

0