PostSharpAPI ReferencePost­Sharp.​Patterns.​ContractsEnum­Data­Type­Attribute
Open sandboxFocus

EnumDataTypeAttribute Class

Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a value that is not a valid member of an enumeration.

Inheritance
EnumDataTypeAttribute
Namespace: PostSharp.Patterns.Contracts
Assembly: PostSharp.Patterns.Common.dll
Syntax
[HasConstraint]
public sealed class EnumDataTypeAttribute : LocationContractAttribute, ILocationLevelAspect, IAspect
Remarks

Strings are matched against enumeration member names. Integers are matched against enumeration member values. Null values are accepted and do not throw exception.

Error message is identified by EnumDataTypeErrorMessage.

Error message can use additional argument {4} to refer to EnumType name.

Constructors

Name Description
EnumDataTypeAttribute(Type)

Initializes a new EnumDataTypeAttribute.

Properties

Name Description
EnumType

Gets the enumeration type.

Methods

Name Description
GetErrorMessage()

Gets unformatted error message as defined by the instance.

GetErrorMessageArguments()

Gets values of additional arguments for error message associated with particular instance of LocationContractAttribute. There arguments can be referenced from error message string by {4}, {5} and so on.

ValidateValue(Byte, String, LocationKind, LocationValidationContext)
ValidateValue(Int16, String, LocationKind, LocationValidationContext)
ValidateValue(Int32, String, LocationKind, LocationValidationContext)
ValidateValue(Int64, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Byte>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Int16>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Int32>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Int64>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<SByte>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<UInt16>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<UInt32>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<UInt64>, String, LocationKind, LocationValidationContext)
ValidateValue(SByte, String, LocationKind, LocationValidationContext)
ValidateValue(UInt16, String, LocationKind, LocationValidationContext)
ValidateValue(UInt32, String, LocationKind, LocationValidationContext)
ValidateValue(UInt64, String, LocationKind, LocationValidationContext)
ValidateValueDynamic(Object, String, LocationKind, LocationValidationContext)
ValidateValueString(String, String, LocationKind, LocationValidationContext)