Open sandboxFocus

Method ToDurableRef

ToDurableRef<T>(T)

Returns a durable reference to a given declaration or type, i.e. a reference that stores only a string identifier and therefore does not keep the compilation in memory.

Declaration
public static IDurableRef<T> ToDurableRef<T>(this T declarationOrType) where T : class, ICompilationElement
Parameters
Type Name Description
T declarationOrType

The declaration or type to reference.

Returns
Type Description
IDurableRef<T>

A durable reference to declarationOrType.

Type Parameters
Name Description
T

The type of the declaration or type, such as IMethod, IProperty or INamedType. It is inferred from declarationOrType.

Remarks

Call this method instead of ToRef() whenever the reference is stored in an object that outlives the current pipeline run, such as a field of a fabric or of an inheritable aspect. The reference returned by ToRef() holds the compilation, and the design-time pipeline keeps such objects across many compilations, so storing one keeps a whole version of the project in memory for as long as the solution is open.

This method produces the same reference as declaration.ToRef().ToDurable() but computes the identifier from the declaration itself, so the intermediate non-durable reference is never created.

A type that is not a declaration, such as an array type or a pointer type, is identified by its SerializableTypeId instead of by a SerializableDeclarationId.

Exceptions
Type Condition
NotSupportedException

The declaration cannot be identified by an identifier, which is the case of an attribute.

See Also