![]() |
Platforms, Frameworks & Libraries »
.NET Framework »
General
Intermediate
License: The Code Project Open License (CPOL)
Type Forwarding in .NETBy Bhupindra SinghType forwarding is a CLR feature that allows us to move a type from its original assembly to another assembly. |
C# (C# 1.0, C# 2.0, C# 3.0), Windows, .NET (.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0, .NET 3.5), Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Type forwarding is a CLR feature that allows us to move a type from its original assembly to another assembly in such a way that there is no need to recompile the applications referring to the original assembly.
Suppose you have created an assembly named MyLibrary which contains a class named MyClass. Let's say, some of your applications refer to the MyLibrary assembly and utilizes MyClass. In a later phase, you decide to move MyClass from MyLibrary to a newly created assembly called MyAdvancedLibrary. If you ship a new version of MyLibrary (which now doesn't have MyClass), along with MyAdvancedLibrary, then your existing applications looking for MyClass in MyLibrary will not find the MyClass and end up with errors.
Now, in order to run your applications without recompiling them, you can use the Type Forwarding feature of the Common Language Runtime.
In the above scenario, you need to apply TypeForwardedToAttribute to the new version of your MyLibrary, so that requests for MyClass are now forwarded to the newly created library MyAdvancedLibrary that now contains MyClass.
MyClass code from MyLibrary to MyAdvancedLibrary.TypeForwardedToAtrribute in MyLibrary for the MyClass type.// C# Example
[assembly:TypeForwardedToAttribute(typeof(MyClass))]
MyAdvancedLibrary.MyAdvancedLibrary into MyLibrary.MyLibrary (because MyClass used to be located in that).Now, you can ship the new version of MyLibrary along with MyAdvancedLibrary and run your applications without a recompile!
The .NET Framework version 2.0 does not allow type forwarding from assemblies written in Visual Basic. However, a Visual Basic application can consume forwarded types if it uses the assemblies coded in C# or C++.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 24 Aug 2008 Editor: Smitha Vijayan |
Copyright 2008 by Bhupindra Singh Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |