The Future of C# (4.0) is awesome

I just attended Anders’ session on what is new in C# 4.0, and I must say, I went in a critic, and came out an enthusiast. Big theme is to be more like VB.NET, such as optional and named parameters, and dynamic invocation of methods.

There are 4 new things in C# 4.0.

Dynamic language features
Optional and named parameters
Better COM-interop
Co-variance

 

Dynamic language features

C# will now have a new keyword called dynamic. With it you can declare a variable, which comes down to the same type as object, but now with dynamic syntax. In C# 3.0 if you have an object reference you need to use reflection to call methods, with C#4.0 you can call any method you know exists on the object.

This is great when using for example Silverlight, because now you can call Javascript code from C# with normal syntax, instead of having to use Invoke. Awesome!!!

Optional and named parameters

Now methods can have optional and named parameters (like VB.NET). Not much to say about that, except for the next bit.

Com-Interop

Talking to COM objects have always been painful. C# 4.0 should make that a lot easier with dynamic invocatioons and optional parameters.

Co-Variance

You can assign an object reference a string object, but you cannot assign reference to a collections of objects a collection of strings. With C# we can now specify whether or not we’ll allow this. So some of the collections and interfaces will now use this syntax and enable some legal scenario’s which are not permitted in C# 3.0.

Don’t use Name as a Property for your own classes in Silverlight 2

Lately I discovered a change in Silverlight 2 (from beta 2) in the handling of names in XAML. If you create an object with a Name property, you cannot set it in XAML (not normally that is).

For example, you have this class:

public class Person
{
  public string Name { get; set; }

  public int Age { get; set; }
}

If you use it in XAML like this the Name property doesn’t get set:

<my:Person
           Name="jefke"
           Age="23">
</my:Person>

Instead XAML will create a reference called jefke pointing to this object.

This sucks of course because there are tons of objects out there that have a Name property, and now we cannot use them in XAML. This is also different from WPF, because there you can use a Name property, and use x:Name to set its namescope. The Name property will still get set normally; to make Name equivalent to x:Name you would use the RuntimeNamePropertyAttribute.

Deploying Silverlight Applications

Yesterday Microsoft announced a new way to get your web server up and running quickly with all required software like IIS and SQL Server (express). Great to get your ASP.NET and Silverlight application out of the door.

More information can be found here.

XAML Power Toys

Tired of typing in XAML to generate your data bound grid in Silverlight? Then check out XAML power toys.

 

“XAML Power Toys is a Visual Studio 2008 SP1 Multi-AppDomain Add-In that empowers WPF & Silverlight developers while working in the XAML editor.  Its Line of Business form generation tools, Grid tools,  DataGrid and ListView generation really shorten the XAML page layout time.

It’s accessed through commands in the XAML editor context menu and the Solution Explorer item context menu.“

Upgrading To Silverlight 2 RTM

 

I’ve been busy upgrading my code to Silverlight 2 RTM, and from time to time I have trouble with the asp:Silverlight control, as if it doesn’t detect the right version of Silverlight. So when I view my application I get this:

image

The solution is easy: In your web project, from references remove the System.Web.Silverlight assembly, and then add it again.