• Haibo Luo's weblog

    Reflection.Emit and Resources

    • 2 Comments
    Reflection.Emit is relatively new to me. Recently I had a chance to deal with a resource related emit issue and had a tough time wading through so many emit APIs with "resource" in their names. Seems they are kind of messy, and I feel the API naming is...
  • 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

    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

    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

    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

    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

    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

    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

    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

    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...
Page 2 of 2 (38 items) 12