Class ManifestItem
Base class used for values which are validated.
Inheritance
Implements
Inherited Members
Namespace: CSF.Validation.Manifest
Assembly: CSF.Validation.Abstractions.dll
Syntax
public class ManifestItem : IManifestNode
Remarks
The validation manifest is the model by which validators are described, including how they should validate objects and values.
The validation manifest objects are not particularly suited to serialization, as they support the use of types that cannot be easily serialized. If you are looking for a way to create/define a validator using serialized data then please read the article Using the Manifest Model.
Properties
| Improve this Doc View SourceAccessorExceptionBehaviour
Gets or sets an optional value which indicates the desired behaviour should the AccessorFromParent raise an exception.
Declaration
public ValueAccessExceptionBehaviour? AccessorExceptionBehaviour { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<ValueAccessExceptionBehaviour> |
Remarks
This option will override the behaviour specified at AccessorExceptionBehaviour for the current manifest value, if this property is set to any non-null value.
If this property is set to null then the behaviour at AccessorExceptionBehaviour will be used.
If IsValue is false then this value is irrelevant and must be null.
See Also
| Improve this Doc View SourceAccessorFromParent
Gets or sets a function which gets (from the object represented by the Parent) the value for the current instance.
Declaration
public Func<object, object> AccessorFromParent { get; set; }
Property Value
Type | Description |
---|---|
System.Func<System.Object, System.Object> |
Remarks
If IsValue is false then this value is irrelevant and must be null.
Children
Gets or sets a collection of the immediate descendents of the current manifest value.
Declaration
public ICollection<ManifestItem> Children { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<ManifestItem> |
CollectionItemValue
Gets or sets an optional value object which indicates how items within a collection are to be validated.
Declaration
public ManifestItem CollectionItemValue { get; set; }
Property Value
Type | Description |
---|---|
ManifestItem |
Remarks
If the value representd by the current instance is a collection/enumerable of items then these items may be validated individually. In this scenario, the ValidatedType must be a type that implements System.Collections.Generic.IEnumerable<T> for at least one generic type.
If this property has a non-null value, then the ManifestItem will be used to validate each item within that collection.
If the current manifest value does not represent a collection of items to be validated individually then this property must be null.
Id
Gets or sets an identifier for the current manifest item.
Declaration
public string Id { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The id of a manifest item is not used by the validator, but it provides a way in which developers may track the lifetime of a single item.
There are no technical reasons why they must be, but developers are encouraged to keep Id values unique within a validation manifest, so that they may identify items unambiguously. The default value for this property is the string representation of a newly-generated GUID.
IdentityAccessor
Gets or sets a function which retrieves a unique identity of the object being validated, given a reference to that object being validated.
Declaration
public Func<object, object> IdentityAccessor { get; set; }
Property Value
Type | Description |
---|---|
System.Func<System.Object, System.Object> |
IsCollectionItem
Gets a value indicating whether or not the ItemType includes the flag CollectionItem.
Declaration
public bool IsCollectionItem { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsPolymorphicType
Gets a value indicating whether or not the ItemType includes the flag PolymorphicType.
Declaration
public bool IsPolymorphicType { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsRecursive
Declaration
public bool IsRecursive { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsValue
Declaration
public bool IsValue { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
ItemType
Gets or sets a value which indicates the type & behaviour of the current manifest item.
Declaration
public ManifestItemTypes ItemType { get; set; }
Property Value
Type | Description |
---|---|
ManifestItemTypes |
MemberName
Where the current value represents a member access invocation (such as a property getter), this property gets or sets the name of that member.
Declaration
public string MemberName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
If IsValue is false then this value is irrelevant and must be null.
OwnChildren
Gets a collection of Children, excluding any children which are exposed via recursion, should IsRecursive true.
Declaration
public IReadOnlyCollection<ManifestItem> OwnChildren { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyCollection<ManifestItem> |
OwnCollectionItemValue
Gets a value equivalent to CollectionItemValue, except that null will be returned if the collection item value is only inherited via recursion, should IsRecursive be true.
Declaration
public ManifestItem OwnCollectionItemValue { get; }
Property Value
Type | Description |
---|---|
ManifestItem |
OwnPolymorphicTypes
Gets a collection of PolymorphicTypes, excluding any types which are exposed via recursion, should IsRecursive true.
Declaration
public IReadOnlyCollection<ManifestItem> OwnPolymorphicTypes { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyCollection<ManifestItem> |
OwnRules
Gets a collection of Rules, excluding any rules which are exposed via recursion, should IsRecursive true.
Declaration
public IReadOnlyCollection<ManifestRule> OwnRules { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyCollection<ManifestRule> |
Parent
Gets or sets the parent of the current manifest item.
Declaration
public IManifestNode Parent { get; set; }
Property Value
Type | Description |
---|---|
IManifestNode |
Remarks
This must be either a ValidationManifest (indicating that this item is the root of the validation manifest data-structure) or another ManifestItem, indicating the parent of the current item.
PolymorphicTypes
Gets or sets a mapping of the runtime types to polymorphic validation manifest definitions for those types.
Declaration
public ICollection<ManifestItem> PolymorphicTypes { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<ManifestItem> |
Remarks
If IsPolymorphicType is true then this collection must be empty.
RecursiveAncestor
Gets or sets a reference to an ancestor manifest item, to which the current item refers.
Declaration
public ManifestItem RecursiveAncestor { get; set; }
Property Value
Type | Description |
---|---|
ManifestItem |
Remarks
If IsRecursive is true then this value must not be null. Otherwise, it must be null.
Rules
Gets or sets a collection of the rules associated with the current value.
Declaration
public ICollection<ManifestRule> Rules { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<ManifestRule> |
ValidatedType
Gets or sets the type of the object which the current manifest value describes.
Declaration
public Type ValidatedType { get; set; }
Property Value
Type | Description |
---|---|
System.Type |
Methods
| Improve this Doc View SourceCombineWithDescendent(ManifestItem)
Combines the current instance with a descendent manifest item.
Declaration
public void CombineWithDescendent(ManifestItem other)
Parameters
Type | Name | Description |
---|---|---|
ManifestItem | other | Another manifest item. |
Remarks
A descendent item might be any of:
- A child item, to be placed in Children
- A collection item value, to be stored at in CollectionItemValue
- A polymorphic type, to be placed in PolymorphicTypes
This method will work with any of these.
This method will silently discard duplicates; so if the other
is reference equal to
the current instance, or if it is already contained within the appropriate property/collection then
it will be ignored and the method will complete without making any change to the state of the current
instance.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If the |
System.InvalidOperationException | If the current item is not eligible to be combined with the specified other item. |
CombineWithDescendents(IEnumerable<ManifestItem>)
Iterates through a collection of manifest items and calls CombineWithDescendent(ManifestItem) upon each. See the documentation for that method for more information.
Declaration
public void CombineWithDescendents(IEnumerable<ManifestItem> others)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ManifestItem> | others | A collection of manifest items to combine with the current instance. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If the |
System.InvalidOperationException | If the current item is not eligible to be combined with any of the other items within the collection. |
MakeRecursive(ManifestItem)
Converts the current ManifestItem into a recursive item, using information
from the specified ancestor
.
Declaration
public void MakeRecursive(ManifestItem ancestor)
Parameters
Type | Name | Description |
---|---|---|
ManifestItem | ancestor | The ancestor item upon which to base the new recursive item. |
Remarks
This process will add the Recursive type to the current instance's ItemType.
Many property values are copied from the ancestor
by this method, as the
recursive item has many of the same properties as its ancestor.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If the |
System.ArgumentException | If the |
ToString()
Gets a string representation of the current instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string which represents the current instance. |