Marks a method or type as constant, indicating that its output depends solely on its input parameters and contains no side effects that affect observable properties.
Implements
Namespace: Metalama.Patterns.Observability
Assembly: Metalama.Patterns.Observability.dll
Syntax
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method)]
public sealed class ConstantAttribute : Attribute, IHierarchicalOptionsProviderRemarks
When the ObservableAttribute aspect encounters a call to a method from a different type, it reports a warning unless the method is known to be constant. A constant method guarantees that subsequent calls with identical arguments will always return the same value and will not affect any observable state.
Methods are automatically considered constant when all their input parameters (including this for instance methods)
are of immutable types, or when the method is a void method without out arguments.
When applied to a type, all methods within that type are considered constant.
As an alternative to this attribute, use ConfigureObservability(IQuery<ICompilation>, Action<ObservabilityTypeOptionsBuilder>) to mark multiple methods as constant using a fabric.
Constructors
| Name | Description |
|---|---|
| ConstantAttribute() |