Wednesday, May 21, 2008

TypeForwaredTo Attribute

I happent to stumbled upon this cool attribute in RunTime.CompilerServices and just couldn't resist blog about it. TypeForwardedTo attribute allows you to move a type from one assembly to another without having to recompile your parent application that uses your original assembly. Now isnt that wonderful ?

Imagine you have send out your application to your users and then you decide to move a datatype you initially created with assembly "a1" to assembly "a2". Now longer would you need to recompile the original application again. Instead, all you need is to send the latest version of "a1" and "a2".

What helps you in this is the TypeForwardedTo Attribute.After moving the code to "a2", you would recompile "a2" and add a reference in "a1". Also you would include following line in your "a1" assembly, preferably in assemblyinfo.

[assembly:TypeForwardedTo(typeof(MyDataType))]

Thats all you need and you are ready to use your New assemblies with your parent application without recompiling it.


Now isnt that a useful one ?