Sign in
Haibo Luo's weblog
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
RSS for posts
Atom
RSS for comments
OK
Search
Tags
DynamicMethod
IronPython
IronRuby
Miscellaneous
Pages
Reflection
Reflection.Emit
VisualStudio
Archive
Archives
April 2010
(1)
March 2008
(5)
October 2007
(6)
September 2007
(3)
August 2007
(1)
November 2006
(7)
October 2006
(2)
August 2006
(1)
July 2006
(1)
April 2006
(1)
February 2006
(2)
January 2006
(2)
November 2005
(2)
October 2005
(2)
September 2005
(2)
August 2005
(3)
Posts
Subscribe via RSS
Sort by:
Most Recent
|
Most Views
|
Most Comments
Excerpt View
|
Full Post View
Haibo Luo's weblog
Type.GetType(string typeName) returns null !?
Posted
over 8 years ago
by
Haibo Luo - MSFT
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
Posted
over 8 years ago
by
Haibo Luo - MSFT
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)
Posted
over 8 years ago
by
Haibo Luo - MSFT
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
Posted
over 6 years ago
by
Haibo Luo - MSFT
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
Posted
over 8 years ago
by
Haibo Luo - MSFT
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
Posted
over 8 years ago
by
Haibo Luo - MSFT
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>
Posted
over 8 years ago
by
Haibo Luo - MSFT
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
VisualStudio as my IronPython editor
Posted
over 6 years ago
by
Haibo Luo - MSFT
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
Take Two: IL Visualizer
Posted
over 7 years ago
by
Haibo Luo - MSFT
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
System.Reflection-based ILReader
Posted
over 7 years ago
by
Haibo Luo - MSFT
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
Posted
over 7 years ago
by
Haibo Luo - MSFT
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 ...
Posted
over 7 years ago
by
Haibo Luo - MSFT
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
My Attribute Disappears
Posted
over 7 years ago
by
Haibo Luo - MSFT
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: Provide (or not) Argument for by-ref Parameter
Posted
over 6 years ago
by
Haibo Luo - MSFT
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
Nested Types in Generic Classes
Posted
over 8 years ago
by
Haibo Luo - MSFT
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?
Posted
over 8 years ago
by
Haibo Luo - MSFT
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
ILVisualizer VS2008 solution
Posted
over 5 years ago
by
Haibo Luo - MSFT
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
IronPython: import clr
Posted
over 6 years ago
by
Haibo Luo - MSFT
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
Hello World with DynamicILInfo
Posted
over 7 years ago
by
Haibo Luo - MSFT
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
IronPython: System.Array
Posted
over 5 years ago
by
Haibo Luo - MSFT
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
Use IronPython to Experiment .NET Libraries
Posted
over 7 years ago
by
Haibo Luo - MSFT
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
Late-bound Array SetValue
Posted
over 7 years ago
by
Haibo Luo - MSFT
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 ...
Posted
over 7 years ago
by
Haibo Luo - MSFT
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: explicitly choose one method
Posted
over 6 years ago
by
Haibo Luo - MSFT
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
IronPython: System.Reflection.Assembly object
Posted
over 5 years ago
by
Haibo Luo - MSFT
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)
1
2