Open sandboxFocus
  • TOC

Metalama Documentation

Getting started

Video tutorials

Conceptual documentation

Commented examples

API documentation

Aspect API

Metalama.​Framework.​Advising

Metalama.​Framework.​Aspects

Aspect2

Aspect­Order­Attribute2

Aspect­Order­Direction

Aspect­Predecessor

Aspect­Predecessor­Extensions

Aspect­Predecessor­Kind

Aspect­Receiver­Extensions

Compilation­Aspect3

Compiled­Template­Attribute2

Compile­Time­Attribute3

Constructor­Aspect3

Contract­Aspect3

Contract­Direction

Declarative­Advice­Attribute2

Editor­Experience­Attribute2

Editor­Experience­Options

Event­Aspect3

Exclude­Aspect­Attribute2

Field­Aspect3

Field­Or­Property­Aspect3

Forced­Generic­Run­Time­Or­Compile­Time­Attribute3

Framework­Diagnostic­Descriptors

IAspect

IAspect<T>

IAspect­Builder

IAspect­Builder<TAspect­Target>

IAspect­Class

IAspect­Instance

IAspect­Predecessor

IAspect­Receiver<TDeclaration>

IAspect­Receiver<TDeclaration, TTag>

IAspect­State

IConditionally­Inheritable­Aspect

IMeta­Target

Inheritable­Attribute2

Interface­Member­Attribute3

Interface­Member­Override­Strategy

Introduce­Attribute3

Introduction­Scope

Invalid­Advice­Parameters­Exception2

Invalid­Template­Signature­Exception2

IObject­Reader

ITemplate­Provider

Layers­Attribute2

meta

Method­Aspect3

Override­Event­Aspect4

Override­Field­Or­Property­Aspect4

Override­Method­Aspect4

Override­Strategy

Parameter­Aspect3

Property­Aspect3

Require­Aspect­Weaver­Attribute2

Run­Time­Attribute3

Run­Time­Or­Compile­Time­Attribute3

Scope­Attribute2

Template­Attribute2

Template­Invocation

Template­Provider

This­Attribute2

Type­Aspect3

Type­Parameter­Aspect3

Metalama.​Framework.​Code

Metalama.​Framework.​Code.​Collections

Metalama.​Framework.​Code.​Comparers

Metalama.​Framework.​Code.​Declaration­Builders

Metalama.​Framework.​Code.​Invokers

Metalama.​Framework.​Code.​Syntax­Builders

Metalama.​Framework.​Code.​Types

Metalama.​Framework.​Code­Fixes

Metalama.​Framework.​Diagnostics

Metalama.​Framework.​Eligibility

Metalama.​Framework.​Fabrics

Metalama.​Framework.​Metrics

Metalama.​Framework.​Options

Metalama.​Framework.​Project

Metalama.​Framework.​Run­Time

Metalama.​Framework.​Serialization

Metalama.​Framework.​Services

Metalama.​Framework.​Utilities

Metalama.​Framework.​Validation

Extensions API

Patterns API

Flashtrace API

Introspection API

Advanced API

Post­Sharp API migration

  • Article

Class ContractAspect

A base aspect that can validate or change the value of fields, properties, indexers, and parameters.

Inheritance
ContractAspect
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)]
[Layers(new string[] { "Build" })]
[Inheritable]
public abstract class ContractAspect : Aspect, IAspect<IParameter>, IEligible<IParameter>, IAspect<IFieldOrPropertyOrIndexer>, IAspect, ICompileTimeSerializable, ITemplateProvider, IEligible<IFieldOrPropertyOrIndexer>
Remarks

A contract aspect can apply to the input or output data flow, or to both data flows, according to the ContractDirection value passed to the constructor. Since the current class does not know the value of this parameter before it is instantiated, this class cannot set the eligibility conditions using the BuildEligibility(IEligibilityBuilder<IFieldOrPropertyOrIndexer>) method. If a derived class targets a specific ContractDirection (i.e. if the choice is not left to the user), its implementation of BuildEligibility(IEligibilityBuilder<IFieldOrPropertyOrIndexer>) can call BuildEligibilityForDirection(IEligibilityBuilder<IFieldOrPropertyOrIndexer>, ContractDirection) methods. This means that eligibility can be checked upfront by the IDE before suggesting the code actions.

In any case, this aspect verifies the eligibility of the target with respect to the specific ContractDirection and target declaration. This verification cannot be skipped.

Constructors

Name Description
ContractAspect()
ContractAspect(ContractDirection)

Initializes a new instance of the ContractAspect class.

Fields

Name Description
BuildLayer

Methods

Name Description
BuildAspect(IAspectBuilder<IFieldOrPropertyOrIndexer>)
BuildAspect(IAspectBuilder<IParameter>)
BuildEligibility(IEligibilityBuilder<IFieldOrPropertyOrIndexer>)

Configures the eligibility of the aspect or attribute. Implementations are not allowed to reference non-static members. Implementations must call the implementation of the base class if it exists.

BuildEligibility(IEligibilityBuilder<IParameter>)

Configures the eligibility of the aspect or attribute. Implementations are not allowed to reference non-static members. Implementations must call the implementation of the base class if it exists.

BuildEligibilityForDirection(IEligibilityBuilder<IFieldOrPropertyOrIndexer>, ContractDirection)

Populates the IEligibilityBuilder for a field, property or indexer when the ContractDirection is known.

BuildEligibilityForDirection(IEligibilityBuilder<IParameter>, ContractDirection)

Populates the IEligibilityBuilder for a parameter when the ContractDirection is known.

GetActualDirection(IAspectBuilder, ContractDirection)

Gets the actual direction of the contract given the direction returned by GetDefinedDirection(IAspectBuilder), after resolving the Default value according to the characteristics of the target declaration, and after taking predecessors and secondary instances into account. The implementation of this method may return None to skip the aspect.

GetDefinedDirection(IAspectBuilder)

Gets or sets the direction of the data flow (Input, Output or Both) to which this contract applies, as defined by the current aspect. This method returns Default by default. When this method returns Default, the actual direction is determined according to the characteristics of the target declaration.

RedirectContracts(IAspectBuilder, IFieldOrPropertyOrIndexer, IParameter)

Redirects validation logic of ContractAspect from the specified property to the specified parameter.

Validate(dynamic?)

Extension Methods