Represents an advice that makes the ahead-of-time compiler (NativeAOT) generate the native code of a type, which the aspect creates by reflection at run time. The advice has no effect unless the project is compiled for NativeAOT.
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public sealed class InstantiateTypeAdviceInstance : AdviceInstanceRemarks
In an application compiled ahead of time, a generic type instance has native code only when the code of the application instantiates
it. A generic type instance over reference types can also be created by reflection, because it shares the native code of the other
instances. A generic type instance over a value type cannot: Activator.CreateInstance throws a NotSupportedException.
An aspect that creates such a type at run time, for instance a formatter or an adapter for the type of a parameter, returns this advice
from ProvideAdvices(object), so that the weaver adds an instantiation of the type to the woven assembly.
The weaver adds the instantiations to a method that is referenced by the module initializer but never called, so that the woven code does not execute them. The type can be internal to another assembly: the runtime never compiles the method, but an IL verifier such as ILVerify reports the access to the internal type.
The advice has an effect only when the MSBuild property PostSharpAotCompatibleWeaving is true. Its default is true
when the project sets PublishAot, IsAotCompatible or EnableAotAnalyzer. Otherwise, the woven assembly is the same
as without the advice. A library whose aspects are used in an application compiled ahead of time must set IsAotCompatible.
Constructors
| Name | Description |
|---|---|
| InstantiateTypeAdviceInstance(Type) | Initializes a new instance of the InstantiateTypeAdviceInstance class. |
Properties
| Name | Description |
|---|---|
| MasterAspectMember | Gets the main field or method of the aspect class that the current AdviceInstance relates to. |
| Type | Gets the type to instantiate. |