Type forwarding is an attribute (implemented in TypeForwardedTo) that allows you to move a type from one assembly (assembly A) into another assembly (assembly B), and to do so in such a way that it is not necessary to recompile clients that consume assembly A. After a component (assembly) ships and is being used by client applications, you can use type forwarding to move a type from the component (assembly) into another assembly and ship the updated component (and any additional assemblies required), and the client applications will still work without being recompiled.
Type forwarding works only for components referenced by existing applications. When you rebuild an application, there must be appropriate assembly references for any types used in the application.
To move a type from one class library to another, follow these steps:
-
Add a TypeForwardedTo attribute to the source class library assembly.
-
Cut the type definition from the source class library.
-
Paste the type definition into the destination class library.
- Rebuild both libraries. The following code shows the attribute declaration used to move TypeA to the DestLibclass library:‘ VBImports System.Runtime.CompilerServices
<Assembly:TypeForwardedTo(GetType(DestLib.TypeA))]>
// C#
using System.Runtime.CompilerServices;
[assembly:TypeForwardedTo(typeof(DestLib.TypeA))]