Method AddContract
AddContract(IParameter, String, ContractDirection, Object, Object)
Adds a contract to a parameter. Contracts are usually used to validate parameters (pre- or post-conditions) or to normalize their value (null-to-empty, trimming, normalizing case, ...).
Declaration
IAddContractAdviceResult<IParameter> AddContract(IParameter targetParameter, string template, ContractDirection direction, object tags = null, object args = null)
Parameters
Type | Name | Description |
---|---|---|
IParameter | targetParameter | The parameter to which the contract should be added. |
System.String | template | The name of the template method. This method must have a single run-time parameter named |
ContractDirection | direction | Direction of the data flow to which the contract should apply. See ContractDirection for details. |
System.Object | tags | An optional opaque object of anonymous type passed to templates and exposed under the Tags property of the meta API. |
System.Object | args | An object (typically of anonymous type) whose properties map to parameters or type parameters of the template. |
Returns
Type | Description |
---|---|
IAddContractAdviceResult<IParameter> |
AddContract(IFieldOrPropertyOrIndexer, String, ContractDirection, Object, Object)
Adds a contract to a field, property or indexer. Contracts are usually used to validate the value assigned to fields properties or indexers or to normalize their value (null-to-empty, trimming, normalizing case, ...)
before assignment. Alternatively, a contract can be used to validate the value returned by a property or indexer, in which case the direction
parameter should be set to Output.
Declaration
IIntroductionAdviceResult<IPropertyOrIndexer> AddContract(IFieldOrPropertyOrIndexer targetMember, string template, ContractDirection direction, object tags = null, object args = null)
Parameters
Type | Name | Description |
---|---|---|
IFieldOrPropertyOrIndexer | targetMember | The field, property or indexer to which the contract should be added. |
System.String | template | The name of the template method. This method must have a single run-time parameter named |
ContractDirection | direction | Direction of the data flow to which the contract should apply. See ContractDirection for details. |
System.Object | tags | An optional opaque object of anonymous type passed to templates and exposed under the Tags property of the meta API. |
System.Object | args | An object (typically of anonymous type) whose properties map to parameters or type parameters of the template. |
Returns
Type | Description |
---|---|
IIntroductionAdviceResult<IPropertyOrIndexer> |