We are happy to announce that S# 1.1 was released today.

## “Extension Methods”

It is now possible extending .NET types with custom methods that can be invoked during script execution. It is not the support for.NET extension methods but functionality is somewhat similar.

Let’s take a .NET “System.Math” class. It is a static class that “Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions”. You can freely access all its members from S# script (omitting namespace) but at some point you may want to extend existing set of methods with some custom or missing (in your opinion) ones. For example conversion to radians, mapping/constraint of numeric values, distance calculation, etc. But “System.Math” is a static class and cannot be inherited for customization purpose.

In S# 1.0 we used the following workaround for such cases: we would have created a “MathEx” class to mimic “System.Math” one with same methods being re-directed to original “Math” plus containing additional members like “Distance()”, “Radians()” etc. After that we’ve been suppressing original “Math” class with our own implementation with the help of RuntimeHost features like “AddType”: **RuntimeHost.AddType(“Math”, typeof(MathEx));** From that moment all “Math.*” calls were redirected to a custom implementation and original “System.Math” was hidden from the scripts.

Though the approach above is still valid and you can easily suppress any type with your own implementation we decided to provide an out-of-box support in S# 1.1 for such scenarios:

RuntimeHost.TypeManager

.AddExtensionMethod(typeof(Math), “Constrain”, new

MathExtensions.Constrain())

.AddExtensionMethod(typeof(Math), “Degrees”, new

MathExtensions.Degrees())

.AddExtensionMethod(typeof(Math), “Distance”, new

MathExtensions.Distance())

.AddExtensionMethod(typeof(Math), “Distance2D”, new

MathExtensions.Distance2D())

.AddExtensionMethod(typeof(Math), “Distance3D”, new

MathExtensions.Distance3D())

.AddExtensionMethod(typeof(Math), “Map”, new

MathExtensions.Map())

.AddExtensionMethod(typeof(Math), “Radians”, new

MathExtensions.Radians());

Now you can create invokable functions and bind them to ANY .net type with a single line of code. The sample above demonstrates how easily “System.Math” type is enriched with 7 new methods. Here’s how I’m using it now within my scripts:

ang1 = **Math.Radians**(i); // convert degrees to radians

ang2 = **Math.Radians**(j); // convert degrees to radians

pos1 = Surface.Width/2 + (sc * **Math.Cos**(ang1));

pos2 = Surface.Width/2 + (sc * **Math.Sin**(ang1));

pos3 = Surface.Width/2 + (sc * **Math.Cos**(ang2));

pos4 = Surface.Width/2 + (sc * **Math.Sin**(ang2));

We hope this feature will greatly reduce development efforts for numerous scenarios as well as well as enrich your scripts.

## Processing# Visualization Language for Silverlight 3.0

“Processing#” is a showcase sample demonstrating most of the powerful capabilities of S#. Being greatly inspired by “Processing” language implementation in Java we decided to port it to Silverlight powering with S# runtime. After installing S# 1.1 runtime you will find the complete source code under the “Samples\Silverlight 3.0” folder.

Solution contains a simple console where you can write and immediately execute scripts. There are more than 30 “Processing.org” samples that were successfully ported to “Processing#” and that are available within the Silverlight console. The syntax was made slightly different by intention and will be getting more parity in later versions.

Source code also contains a ported to Silverlight demo from “OpenProcessing.org” to demonstrate the capabilities of Processing# powered by S# 1.1 runtime:

*function Setup()
*

*{
*

*Surface.Size(320, 480);
*

* //Main Body
*

*Surface.Defaults.StrokeThickness = 2;
*

*Surface.Defaults.Fill = new SolidColorBrush(Color.FromArgb(255, 203, 224, 142));
*

* using (Surface)
*

* {
*

* BeginShape();
*

* Vertex(154, 65);
*

* Vertex(182, 71);
*

* Vertex(225, 82);
*

* Vertex(250, 90);
*

* Vertex(258, 96);
*

*…
*

The image above is rendered by Silverlight 3 and has no visual difference comparing to that created by Java.

You can download the latest runtime with Processing# demo here: Orbifold S# Runtime 1.1