ToRef()
Gets a reference that can be used to identify the current declaration across different compilation versions.
Declaration
IRef<IPropertyOrIndexer> ToRef()Returns
| Type | Description |
|---|---|
| IRef<IPropertyOrIndexer> | A compile-time serializable reference to the current declaration. |
Remarks
References are essential in Metalama because IDeclaration objects are bound to a specific ICompilation. As aspects execute, the compilation evolves through multiple immutable versions. References provide a stable way to track the same declaration across these versions.
Common use cases:
- Storing declaration references in aspect fields for use in later compilation versions.
- Serializing references for cross-project scenarios (inheritable aspects, validators).
- Passing references to child aspects via IAspectState.
To resolve a reference back to the declaration, use GetTarget<T>(IRef<T>) or GetTarget<T>(IRef<T>, ICompilation, IGenericContext?).