C#, VB.NET To Get Windows Runtime Support, Asynchronous Methods

C# and VB.NET will soon be getting new features like Windows Runtime Support, Asynchronous Methods, Caller Info attributes and more. Also, compiler will get APIs which will expose what the compiler knows about the code to the IDE and the developers.

Windows Runtime Support – C# and .NET now have deep integration with the Windows Runtime – a C# project can compiled into a WinMD file and then referenced from a HTML/JavaScript project. We have covered this in more detail on InfoQ earlier.

Asynchronous methods – this simpler way to write asynchronous tasks with the async and await keywords was first demonstrated in PDC last year and then previewed in an Async CTP. Thesearticlesexplore this feature in more detail

Caller Info Attributes – new attributes CallerFilePath, CallerLineNumber and CallerMemberName that can be used against optional method parameters, which will help in getting more details about the caller without having to pass it from the calling method

Compiler APIs – This one is supposed to come after C# 5.0 – the APIs will expose whatever knowledge the compiler has about the code to the IDE and the developers through Syntax Tree APIs, Symbol APIs, Binding and Flow analysis APIs and Emit APIs. You can get more details in this Microsoft Research video.

These new features are going to make things easier for .NET developers. For instance, this is a common pattern for property changed notifications -

publicclassCustomer : INotifyPropertyChanged

{

publiceventPropertyChangedEventHandler PropertyChanged;

privatestring _firstName;

publicstring FirstName

{

get { return _firstName; }

set { Set(ref _firstName, value, "FirstName"); }

}

privatevoid Set<T>(ref T field, T value, string memberName)

{

if (!object.Equals(field, value))

{

field = value;

if (PropertyChanged != null)

PropertyChanged(this, newPropertyChangedEventArgs(memberName));

}

}

}

The problem with this pattern is that it is real easy to mess it up. If you misspell the property name in the setter, or rename the property, then it will silently fail.

Similarly, asynchronous programming will now be much easier and cleaner to use, and will probably be used more often – a good thing consider touch interfaces will need most methods to be asynchronous. Silverlight developers especially will get reprieve. And like the “Paste as VB” and “Paste as C#” demo that Anders shared, Compiler APIs will bring in a lot of possibilities for .NET tooling vendors. Looks like interesting times ahead!

I'd love to be proved wrong, but I'm not sure your example for CallerMemberName will work. I'm guessing that the property names will be prefixed with get_ and set_ as those are the actual member names. Though in that case you could of course check and strip the prefix.