Posts

Showing posts with the label reflection

A Good Mix 19: Reflection, the Silverlight Toolkit, Dynamic JSON, libraries, builds and more

A collection of blog entries and articles on IronPython and the Dynamic Language Runtime from the last few weeks. Speed Test: Reflection vs IronPython Randall Sutton was using reflection to apply rules to an object when he realised he could do it with IronPython, but he was worried about performance. He wrote a quick test to compare the performance and was surprised by the results. The first run was very expensive for IronPython, but from there on in IronPython was much faster than C#. Without expending any effort actually working it out, my guess is that because IronPython uses reflection so heavily it caches the reflection lookups - and it is this caching that is giving it the performance benefit. Reflection on .NET is not fast, by any stretch of the imagination, and improving the performance of reflection would make a big difference to speeding up DLR languages. The Silverlight Toolkit and the Dynamic Language Console The Silverlight Toolkit is an open source project by Microsoft ...

A Good Mix 10: WPF, .NET Introspection, the Solver Foundation, Resolver One and Cobra

Another selection on a wide range of topics from the last few weeks. Resolver One 1.5 Release Resolver One is an IronPython spreadsheet system and is the largest IronPython codebase in production. Normally a new release would be big news but we've already covered the Python console which is the biggest new feature in version 1.5. Other big new features include CSV import / export and a goto line dialog for the code editor. You can read a full list of all the improvements in the changelog . Now that 1.5 is out we're working hard on features for version 1.6. Our latest blog entry has a sneak preview of one of the coming attractions . Introspecting .NET Types and Methods from IronPython For Python methods you can use the inspect module to get information about methods / functions; like what arguments they take and so on. Methods on .NET types don't have the attributes used by inspect (although methods of Python objects defined in IronPython work fine). We can get around thi...

Methodist: Make .NET Reflector come alive with IronPython

No, not a reference to a once dynamic spiritual movement that is now largely part of the institutionalised church, but a new plugin for .NET Reflector . Reflector is a tool for exploring and disassembling .NET libraries. From binary assemblies it will show you all the classes and their members including the relationships between them. It will also disassemble them back into C# or VB.NET source code; invaluable for understanding the behavior of objects but a nightmare if you feel the need to protect your source. Ben Hall , UK MVP, C# expert and dynamic languages enthusiast has created a plugin for Reflector which makes it even more useful. Part of the power of dynamic languages is how easy they make exploration from the interactive environment. Ben has brought this to Reflector by embedding an IronPython interpreter (REPL). Whilst you are looking at the available methods and their arguments and return values you can actually instantiate classes and use them from the interpreter. As wel...

Exploring ActionScript Bytecode with IronPython

OK, so I'm not fully certain what this about - but it certainly looks interesting. AbcExplorationLib is " a library to read and write ActionScript Byte Code (ABC) files. When completed it could be used for compiled program analysis or as part the back end of an experimental compiler. It is written in F# but it could be used from other .NET languages. Inspiration for this library comes from many excellent libraries for bytecode manipulation such as BCEL, ASM, Cecil or System.Reflection.Emit ". The blog entry linked to here, is about experimenting with ActionScript bytecode from IronPython; and in particular with the bytecode for the switch statement. Support for the LookupSwitch opcode in AbcExplorationLib Given the following ActionScript code: var x; for(x = 1;x switch(x) { case 1: print("one"); break; case 2: print("two"); break; case 3: print("three"); break; case...

Checking Type Contract from IronPython

Ronnie Maor blogs about testing a C# interface interface that is implemented in IronPython. As Python is generally much more relaxed he needs to ensure that IronPython honours the type contract of the interface it is implementing. He tests this by testing the Python code through the C# interface (which will complain loudly if you use the wrong types) - making the calls via reflection. Checking Type Contract from IronPython " One thing I wanted to test is that my class implements the C# interface correctly in terms of methods' signatures. Otherwise IronPython throws an exception when it tries to map the arguments to the python method, or when it tries to convert the return value. However, my tests are in python, and calls to the object from python don't go through the type checking/conversion parts. " " To overcome this, I call the methods using .NET reflection, which mimics a C# call more accurately and goes through the type checking code. Here's the utility ...

Adding References to Assemblies in IronPython

The 'first point' of interoperation between Python code and the .NET framework is the clr module. This allows you to dynamically add references to .NET assemblies in order to be able to import classes from the namespaces they contain. The clr module has a bewildering array of different functions for adding references to assemblies, and each of them have slightly different semantics and use cases. Dino Veihland (IronPython Developer) recently posted a very useful explanation to the mailing list: clr.AddReference(str) will first try Assembly.Load and then try Assembly.LoadWithPartialName - this should mean that trying with the strong name won't do anything because LoadWithPartialName will do that for you. This is kind of the one-stop shopping for loading assemblies in the GAC or the app base. If those don't work it will also ultimately search sys.path when the load fails. clr.AddReference(asm) will just add the assembly that you've already loaded - this is u...

Exploring Test Application

The GUI Automated Testing blog explores testing .NET applications with reflection, via IronPython. Exploring Test Application - IronPython (1)

Signature Resolver in IronPython

Haibo Luo explores .NET introspection using IronPython - examining method signatures (and local variables) for dynamic methods: Signature Resolver

Get List of Types from Assembly in IronPython

Saqib Ullah shows how easy .NET reflection is in IronPython by listing all the types in an assembly: Get List of Types from Assembly in IronPython

Nauman Leghari's on IronPython, GLEE, Cecil and More (Graphs)

Nauman Leghari blogged recently on IronPython and Cecil : Fun with IronPython & Cecil Part I Fun with IronPython & Cecil Part II "Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. It has full support for generics, and support some debugging symbol format. In simple English, with Cecil, you can load existing managed assemblies, browse all the contained types, modify them on the fly and save back to the disk the modified assembly." He has followed thes up with: Fun with IronPython & GLEE GLEE is a .NET tool for graph layout and viewing. It has been developed in Microsoft Research. and then: Method Tree Visualizer :: Fun with IronPython, Cecil and Netron Graph - Part III As I said in the last post, the output from Microsoft GLEE looked but not ideal and as the method tree gets bigger with more relationships, the diagram gets out of control. Disappointed with that, my further search takes me to the Netron P...