IronRuby, IronPython and DLR Daily Builds RSS Feed Is Available!

With the help of Harry Pierson (AKA DevHawk), there is an RSS feed that will notify you when a new nightly build is available!image 
The builds are daily and you get the latest versions of IronRuby, IronPython and the DLR in Silverlight or desktop versions.

So all of you early adapters, go ahead and subscribe to the feed!

Comment: the files in the feed are the built files, not the source code.

Enjoy,
Shay.


IronLanguages and Cross-Platformability

Most dynamic languages can run on multiple platforms. IronPython and IronRuby are no exception. The dev teams are investing lots of resources in order to make this happen because of the importance of this feature to the community.

IronPython and IronRuby can be run on top of Mono, which enables you to run .Net applications on top of different platforms, including Linux, BSD, Mac and more.

mono-gorilla

There are some great posts that show you how to do that:

Enjoy the cross-platformability! :)
Shay.


The dynamic Keyword Part 2 – IDynamicObject

This is the second part of my series about the new dynamic keyword in C# 4 (Read the first post here).

As I talked on the first post, the dynamic keyword does the dirty reflection work for you. This is very nice, but it’s like moving forward from a desktop computer to a 10kg laptop – you get to be more dynamic, but it’s still heavy to move around…

The first laptop - heavy!

The dynamic keyword holds a greater power inside, and this is what I’m going to talk about today – the IDynamicObject interface.

What is the IDynamicObject interface?

When we declare an object as dynamic and execute actions upon it, we actually use a default IDynamicObject implementation.

The IDynamicObject interface has a few methods, the important ones (for this post) are – Invoke, GetMember and SetMember.
The idea is very simple -

dynamic myObject = GetIDynamicObject();
myObject.SomeProperty = "Hello"; // This calls IDynamicObject.SetMember
Console.WriteLine(myObject.SomeProperty); // This calls IDynamicObject.GetMember
myObject.RunSomething(); // This calls IDynamicObject.Invoke

This means that we can implement our own behavior for the dynamic invocation! let’s see what we can do with that…

What can I do with that?

If we implement our own IDynamicObject, we can ease the pain of various daily operations. For example, we can develop an IDynamicObject that will give us the ability to use un-typed datasets as if they were typed. Another example can be an implementation that will enable us to dot through an xml file, with no need of XmlDocument, xpath and their friends. I’m sure there are tons of other uses that can and will be implemented.

Sample IDynamicObject implementation – Working with un-typed datasets

The first thing we’ll do is to create an extension method to the System.Data.DataSet class:

public static class Extensions
{
public static dynamic AsDynamic(this DataSet dataSet)
{
return new DataSetDynamicCaller(dataSet);
}
}
When we call DataSet.AsDynamic(), we’ll receive a DataSetDynamicCaller class in return, as a dynamic type object. 

Now what we need to do, is to generate classes that dynamically access the dataset objects. This is a very easy process as you will see in just a moment.

So let’s create the DataSetDynamicCaller class:

public class DataSetDynamicCaller : DynamicObject
{
DataSet dataset;

public DataSetDynamicCaller(DataSet dataset)
{
this.dataset = dataset;
}

public override object GetMember(System.Scripting.Actions.GetMemberAction info)
{
return new dataset.Tables[info.Name];
}
}

This is it… Now to the explanation…

Firstly, I inherit from DynamicObject – this is the basic implementation to the IDynamicObject interface (download link is at the end of the post). As I understand, the DynamicObject class will be a part of the System.Dynamic namespace in C# 4, so you won’t need this file on the final version. I won’t deep dive into this implementation, it’s a subject to another post.

Secondly, The DataSetDynamicCaller class is very simple – we get the untyped dataset in the constructor and save it in a private member. Then, whenever the user asks for a property, we return a DataTable that matches the name of the requested member.
This will give us the ability to call a table directly. For example:

DataSet ds = new DataSet();
ds.Tables.Add("MyTable");

dynamic dynDS = ds.AsDynamic();

DataTable tbl = dynDS.MyTable; // This will work!

It’s as simple as that!

I attach the class I’ve written (the link is at the end of the post). The sample contains two more classes and enables you to use the un-typed dataset even more easily. For instance, calling dynDS.MyTable.GetRow(0).MyColumn will return the value of the MyColumn column from the first row of the MyTable table…

In conclusion, the IDynamicObject interface opens a large amount of possibilities for improving our everyday work in a lot of aspects. It starts from accessing untyped datasets as if they were typed and ends where your imaginations does. This is what they mean when they say dynamic capabilities!

image

Downloads:
DynamicObject.cs
DynamicDataSet.cs

All the best,
Shay.

kick it on DotNetKicks.com
Shout it


IronRuby Code Repository Changes

Starting from today, you will not get new updates from the IronRuby SVN code repository. The repository has been moved to github, and SubVersion has been replaced with Git.

If you want the source code, you’d need to adjust your code with the new changes.

If you don’t need the code, only the builds, you can now download the latest 0.2 version as a zip file (that contains the needed DLLs and batch files). Soon enough you’ll be able to download daily builds as well – so the need for the source code reduces or even disappears for those who only wish to work with IronRuby.

The 0.2 version, the daily builds (coming soon) and the links to the Git repository can be found on the download page at: http://www.ironruby.net/Download.

All the best,
Shay.


IronRuby.net Was Recently Updated With a Brand New IronRuby Logo!

The IronRuby.net site (the official IronRuby site) has recently changed it layout from a kind of childish layout to a slicker one.  The new layout comes with a new IronRuby logo! here it is:

ironrubylogoIt’s a nice and simple logo – stays true to its roots :)

Some other updates to the site – the Roadmap page has been updated and it now contains the “must-have” and “nice-to-have” items for the first release of IronRuby. Quite an interesting list, worth a look.

 

All the best,
Shay.


IronRuby Tip: Ruby String and ClrString

When you use IronRuby to execute some C# code, for example, and the C# code returns a string, pay  IronRuby Tip: Ruby String and ClrStringattention that the string is not a Ruby string!
The type of the object you receive is ClrString. ClrString is the equivalent of System.String in IronRuby, all the System.String methods will work on ClrString objects, but Ruby’s string methods will not (and vice versa).

For example:

clr_string = MyCSharpNameSpace::MyClass.ReturnString()

clr_string.IndexOf("something") # This will work
clr_string.EndsWith("something") # This will work

clr_string[0..2] # This will NOT work
clr_string.index("something") # This will NOT work

As you can see, the System.String methods work but the Ruby string methods don’t.

What to do?

If you want to use a System.String as a Ruby string, all you have to do is call to_s! just like that:

clr_string = MyCSharpNameSpace::MyClass.ReturnString()

clr_string = clr_string.to_s # Converting the ClrString to a Ruby string

clr_string[0..2] # This will WORK!
clr_string.index("something") # This will WORK!

Just to make clear – you will not be able to use System.String methods after the conversion to a Ruby string… One language at a time, folks, one language at a time :)

All the best,
Shay.


Subscribe Subscribe

That's Me!

Hi! I'm Shay Friedman
I'm Shay Friedman - a Visual C#/IronRuby MVP, a consultant and instructor of .NET technologies, author, speaker and new technologies freak
More about me

Contact Me

> Contact page
> Twitter: @ironshay
> LinkedIn profile

Search

Hosted By

I'm hosting this site on Arvixe and I'm very happy with it.
If you're looking for ASP.NET hosting, I highly recommend it
(and if you order from this link I also get some beer money!)
Web Hosting