IronShay

Ironing code, geek t-shirts and even presentations!

NAVIGATION - SEARCH

WinForms in IronRuby

IronRuby holds so much potential. I can say from my perspective, that since I’ve been playing around with it, I became more and more enthusiastic about it and sure that it’s going to succeed big time.

However, IronRuby still has a few drawbacks. They focus mainly on the the lack of Visual Studio support and its side-effects. WinForms is one of the technologies that suffer from this shortcoming. Do you expect me to develop WinForms without the precious designer? I know everyone has their love-hate relationship with the VS designer, but taking it away entirely is just too much to handle.

Well, that’s what I’m here for - to hand you a solution!

I’ve written an IronRuby script (actually, it will run on MRI as well) that will convert a winform designer code (C# only currently) to IronRuby code. By using the script, you can use the VS designer and create the form you want. After you’re finished, run the script and voila – you have all the designer code in IronRuby code!

I won’t explain the code here (maybe I’ll write another post about it, not sure) but in short, it uses regular expressions to find several C# things and replaces them to ruby things…

The file

The ruby source file can be downloaded from here.

(if someone is willing to help me uploading it to GitHub, please do :) ).

How to use it?

First, you need to load the ruby library. The file is named “win_forms_converter.rb” so just start by requiring it:

require “win_forms_converter.rb” # Assuming it appears within the current directory

The library contains one single method accessible from WinFormsConverter.convert_winform. The method receives three parameters:

  • designer_file – the path to the form designer file. For example, C:\Dev\WinForm\Form1.designer.cs.
  • target_file – the path of the new IronRuby file. For example, C:\Dev\IronRubyWinForm\Form1.rb.
  • target_main_file – optional parameter. The path of the form runner file. If this parameter exists, a file will be created on the given path that executes the created form. For example, C:\Dev\IronRubyWinForm\main.rb.

REPL Example

This is a sample command prompt session for converting a WinForm to IronRuby and run it:

______________________

C:\>d:

D:\>cd demo

D:\Demo>ir
IronRuby 0.5.0.0 on .NET 2.0.50727.4016
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require  "win_forms_converter.rb"
=> true
>>> WinFormsConverter.convert_winform('Form1.designer.cs','D:\Demo\IR\form1.rb','D:\Demo\IR\main.rb')
Converting designer file from Form1.designer.cs
Done.
Creating IronRuby file at D:\Demo\IR\form1.rb
Done
Creating main file at D:\Demo\IR\main.rb
Done
Conversion is finished.
=> nil
>>> exit

D:\Demo>cd IR

D:\Demo\IR>ir main.rb

_______________________

Pay ATTENTION

This is the very very first version of this convertor. I haven’t tested it deeply and I’m kind of freeing it to the wild so you people can take it and make it much better.

If you need any explanation about the source  code, you have comments, you’ve found bugs or whatever, you’re welcome to contact me via the contact page or via twitter @ironshay.

Hope it helps,
All the best,
Shay.

Pingbacks and trackbacks (5)+

Add comment