Archive for April 2010
A while back I posted a simple way of using IronPython to configure a .NET application. The I spotted Herman’s question about whether the application would react to a change in the Configuration.py file. The way I wrote the original sample the configuration is read in once. But it’s fairly simple to modify the code to react to changes in Configuration.py. Here’s the modified Program class:
static void Main(string args)
FileSystemWatcher watcher = new FileSystemWatcher(AppDomain.CurrentDomain.BaseDirectory, "*.py");
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastWrite;
DateTime modified = DateTime.Now;
Console.TreatControlCAsInput = true;
dynamic configuration = ConfigureFromIronPython();
watcher.Changed += (sender, eventArgs) =>
if (DateTime.Now - modified > TimeSpan.FromMilliseconds(100))
modified = DateTime.Now;
configuration = ConfigureFromIronPython();
Console.WriteLine("Press any key to exit...");
watcher.EnableRaisingEvents = false;
private static dynamic ConfigureFromIronPython()
dynamic configuration = new ExpandoObject();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
private static void DisplayConfiguration(dynamic configuration)
for (int i = 0; i < configuration.Count; i++)
By adding a FileSystemWatcher, we can react to changes in Configuration.py and update the application configuration. (If you’re wondering the check of when the last modification occurred is to prevent handling the same change twice which can occur when using the FileSystemWatcher.) The only other change is a minor refactoring to extract a method that displays the configuration.
As you may have noticed, IronRuby 1.0 was released earlier this week. I downloaded the .NET 4.0 version and headed to the Samples folder – in there, I noticed, is a Tutorial folder. There’s a file called tutorial.bat, so I opened a command line in that folder and ran the batch file. And I was impressed to be presented with an IronRuby Tutorial:
There are three tutorial options available: an IronRuby Hosting Tutorial; an IronRuby Tutorial and a Try Ruby Tutorial.
So, if you’ve been meaning to get to grips with IronRuby, these tutorials could be just what you’ve been waiting for.
Yesterday I was at TechDays 2010, where I presented a session on what’s new in VB 10 and C# 4.0. Before diving into the new features, I talked about the trends in language design and evolution – for those who are interested, I’d take a look at this session where Anders Hejlsberg goes into far more detail. Next I picked out a few personal highlights of what’s new in .NET 4.0 – including Code Contracts, Tuples and In-Process Side-By-Side Execution and talked briefly about co-evolution. The new VB features I talked about were Auto-implemented Properties, Implicit Line Continuation, Collection Initializers and Statement Lambdas. The new C# features I discussed were Optional and Named Parameters and Dynamically Typed Objects – of course no discussion of Dynamically Typed Objects would be complete without mentioning the Dynamic Language Runtime and I also talked about ExpandoObject and DynamicObject and how both C# and VB can use this new dynamic capability. The last two features are new to both C# and VB: Improved COM Interoperability and Co- and Contra-Variance.