Type Forwarding (C++/CLI)
Type forwarding allows you to move a type from one assembly (assembly A) into another assembly (assembly B), such that, it is not necessary to recompile clients that consume assembly A.
This feature is not supported in all runtimes.
This feature is not supported in the Windows Runtime.
Common Language Runtime
The following code example demonstrates how to use type forwarding.
#using "new.dll" [assembly:TypeForwardedTo(type::typeid)];
The assembly into which you are moving the type definition.
The type whose definition you are moving into another assembly.
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, ship the updated component (and any additional assemblies required), and the client applications will still work without being recompiled.
Type forwarding only works for components referenced by existing applications. When you rebuild an application, there must be the appropriate assembly references for any types used in the application.
When forwarding a type (Type A) from an assembly, you must add the
TypeForwardedTo attribute for that type, as well as an assembly reference. The assembly that you reference must contain one of the following:
The definition for Type A.
TypeForwardedToattribute for Type A, as well as an assembly reference.
Examples of types that can be forwarded include:
You cannot forward the following types:
Nested types (if you want to forward a nested type, you should forward the enclosing type)
You can forward a type to an assembly authored in any language targeting the common language runtime.
So, if a source code file that is used to build assembly A.dll contains a type definition (
ref class MyClass), and you wanted to move that type definition to assembly B.dll, you would:
MyClasstype definition to a source code file used to build B.dll.
Build assembly B.dll
MyClasstype definition from the source code used to build A.dll, and replace it with the following:
#using "B.dll" [assembly:TypeForwardedTo(MyClass::typeid)];
Build assembly A.dll.
Use A.dll without recompiling client applications.