IronPython: Keyword Argument to Set .NET Property/Field

Use keyword arguments to set properties or fields… you likely ask the question: where can we do this? IronPython allows it in the constructor call, the call against the .NET type. Such keyword should be the name of public field, or property (which is not read-only). After creating the object instance, each keyword argument value…


IronPython: Passing Arguments for a Call

After getting a CLR type, we can play it like a python type. We can get the class/static methods using the dot operator (“attribute reference”) on the type, or create an instance of it and then get the instance methods. In Python’s word, these methods are callable objects, and we can make “calls” on them…


IronPython: Grab the .NET Type

After loading the assembly by clr.AddReference and then import namespace, we are ready to take hold of types and down-level namespaces using “attribute references”. >>> import System>>> System.DateTime                    # type<type ‘DateTime’>>>> System.Diagnostics                 # still namespace<module ‘Diagnostics’ (CLS module, 2 assemblies loaded)>>>> System.Diagnostics.Debug           # type again<type ‘Debug’>>>> System.Diagnostics.CodeAnalysis    # namespace again<module ‘CodeAnalysis’ (CLS module from mscorlib,…


IronPython: clr.AddReference

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 clr.AddReferenceToFile clr.AddReferenceToFileAndPath clr.AddReference accepts System.Reflection.Assembly objects and/or assembly names. The typical usage looks like: asm = … # any approach of…

5

IronPython: import clr

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. In IronPython, python type str is implemented by the .NET type System.String. We can call…


DebuggerTypeProxy for IronPython Old-style Class and Instance

First I want to make it clear that this post means nothing related to IronPython’s plan about debugging python code in the future; it serves more as an interesting example to demonstrate DebuggerTypeProxyAttribute and how types can be created dynamically and be used in the VS debugger windows to display information the end users are…

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…


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