• Haibo Luo's weblog

    Type.GetType(string typeName) returns null !?

    • 7 Comments
    Type.GetType gives us the ability to get type back from a string. We pass a well-written type name string to it, and expect it return that type. Sometimes, to your surprise, it returns null. For example, Type.GetType("System.Data.SqlClient.SqlException...
  • Haibo Luo's weblog

    Activator.CreateInstance and beyond

    • 12 Comments
    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...
  • Haibo Luo's weblog

    DebuggerVisualizer for DynamicMethod (Show me the IL)

    • 11 Comments
    Have you ever tried DynamicMethod, one of the coolest features in the .NET 2.0? Hope you have; otherwise, you can try it now with the examples 1 , 2 . Like emitting IL to MethodBuilder, we first get ILGenerator from a DynamicMethod, and make a series...
  • Haibo Luo's weblog

    IronPython: clr.AddReference

    • 5 Comments
    In order to interop with .NET libraries, we need first load in the assemblies we want to play with. The family of AddReference methods in the clr module serves the purpose. clr.AddReference clr.AddReferenceByName clr.AddReferenceByPartialName...
  • Haibo Luo's weblog

    Read IL from MethodBody

    • 4 Comments
    Reflection in .NET 2.0 ships with a new class MethodBody, which "provides access to information about the local variables and exception-handling clauses in a method body, and to the Microsoft intermediate language (MSIL) that makes up the method ...
  • Haibo Luo's weblog

    Get Names and Values of Enum Members

    • 2 Comments
    Yes, reflection can get this done. Assume we have an Enum type - Colors, the following code will print the name and value for each member of it. foreach ( FieldInfo fi in typeof ( Colors ).GetFields( BindingFlags .Public | BindingFlags .Static...
  • Haibo Luo's weblog

    Reflection and Nullable<T>

    • 4 Comments
    You might have already read this : VS2005 made the last-minute DCR related to boxed Nullable<T>. Runtime now treats Nullable<T> differently from other generic value types when boxing: Int32 ? x = null ; object y = x; ...
  • Haibo Luo's weblog

    Take Two: IL Visualizer

    • 6 Comments
    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...
  • Haibo Luo's weblog

    VisualStudio as my IronPython editor

    • 9 Comments
    The following steps are what I did to get Visual Studio ready as my IronPython (and IronRuby) editor. Install the latest internal dogfood build of Visual Studio 2008. you may use Visual Studio 2005 or download the VS 2008 public beta2 ; ...
  • Haibo Luo's weblog

    System.Reflection-based ILReader

    • 2 Comments
    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...
  • Haibo Luo's weblog

    Turn MethodInfo to DynamicMethod

    • 2 Comments
    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...
  • Haibo Luo's weblog

    Member Order Returned by GetFields, GetMethods ...

    • 9 Comments
    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...
  • Haibo Luo's weblog

    IronPython: System.Array

    • 1 Comments
    When you start interop'ing with .NET in IronPython, sooner or later, you will find that you are in need of creating an array as argument. There are mainly 2 ways to create array objects: Array with type indexing (for one-dimensional array object only...
  • Haibo Luo's weblog

    IronPython: Provide (or not) Argument for by-ref Parameter

    • 1 Comments
    Python function may return multiple objects as a tuple. The .NET method can only return one object as the result of a call; in order to return more than one objects, by-ref parameters are needed. They are decorated with the parameter modifier (ref, out...
  • Haibo Luo's weblog

    My Attribute Disappears

    • 3 Comments
    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...
  • Haibo Luo's weblog

    IronPython: import clr

    • 0 Comments
    clr is an IronPython built-in module, which provides some functionalities in order to interop with .NET. When writing "import clr" in a python module, it means you intend to leverage the .NET libraries. One classical example is python string's methods...
  • Haibo Luo's weblog

    Nested Types in Generic Classes

    • 1 Comments
    In C#, nested types can be defined in generic classes just like they would be in non-generic classes. For example: class G <T> { public class NestedC { } public enum NestedEnum { A, B } } Inside the nested type NestedC...
  • Haibo Luo's weblog

    ILVisualizer VS2008 solution

    • 5 Comments
    I attached the ILVisualizer VS2008 solution in this post. There is no source code update; the only change is to upgrade the Microsoft.VisualStudio.DebuggerVisualizers.dll reference from version 8.0.0.0 to version 9.0.0.0. Just for your convenience...
  • Haibo Luo's weblog

    No LocalVariableInfo.Name?

    • 0 Comments
    This was one ladybug in MSDN product feedback center. First of all, thanks to those who filed bugs or suggestions through it, which really help improve our product quality. No Name property in the LocalVariableInfo class is "by design...
  • Haibo Luo's weblog

    Hello World with DynamicILInfo

    • 5 Comments
    The following "Hello World" program shows how to use APIs in the class DynamicILInfo . MSDN documentation will have more details on this class in the next release. using System; using System.Reflection; using System.Reflection...
  • Haibo Luo's weblog

    Use IronPython to Experiment .NET Libraries

    • 2 Comments
    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...
  • Haibo Luo's weblog

    IronPython: explicitly choose one method

    • 0 Comments
    C# allows method overloading. Given an argument list, the compiler performs the overload resolution to select the best method to invoke. The chosen method token is baked into the assembly. IronPython does the method resolution at the IronPython run time...
  • Haibo Luo's weblog

    Late-bound Array SetValue

    • 0 Comments
    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...
  • Haibo Luo's weblog

    Type.FullName returns null when ...

    • 2 Comments
    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...
  • Haibo Luo's weblog

    IronPython: System.Reflection.Assembly object

    • 1 Comments
    IronPython offers a little bit more love to the Assembly object instance: we can directly access the assembly's top-level members (namespace, public type) via the dot operation. System.Reflection provides many ways to let you hold the assembly object...
Page 1 of 2 (38 items) 12