Cast<TSource, TTarget>(TSource)
At post-compile time, casts an instance of a type to another type. A post-compile time error is reported if the source type cannot be assigned to the target type.
Declaration
public static TTarget Cast<TSource, TTarget>(TSource o) where TSource : class where TTarget : classParameters
| Type | Name | Description |
|---|---|---|
| TSource | o | The instance to cast. |
Returns
| Type | Description |
|---|---|
| TTarget | The object |
Type Parameters
| Name | Description |
|---|---|
| TSource | The source type. |
| TTarget | The target type. |
Remarks
The purpose of this method is to make source code compilable even when
an interface is implemented at post-compile time.
PostSharp ensures that TTarget is assignable from
TSource. If it is, the call to this method is
suppressed. If the types are not assignable, a build error is issued.
Use it, for example, to access an interface introduced by an aspect from the source code of the target class.