Base class for providers of contract error messages.
Namespace: PostSharp.Patterns.Contracts
Assembly: PostSharp.Patterns.Common.dll
Syntax
public class ContractLocalizedTextProvider : LocalizedTextProviderRemarks
An implementation typically overrides the GetMessage(string) method. This method returns a formatting string where the first four parameters have a well-known meaning:
| Parameter | Description |
|---|---|
| {0} | The name of the declaration being validated. It is empty for a return value. |
| {1} | The kind of the declaration being validated. |
| {2} | The name and kind of the declaration being validated. |
| {3} | The invalid value. |
To change or translate error messages, derive a class from ContractLocalizedTextProvider, override GetMessage(string) to return your own text for the message identifiers that you handle, and call the base implementation for the others. At application startup, assign an instance of your provider to LocalizedTextProvider, and pass the previous value of this property to the constructor. The identifiers of the messages of built-in contracts are the constants of this class. A custom contract can use its own identifier if a provider of the chain defines it; when no provider defines an identifier, GetMessage(string) throws an ArgumentOutOfRangeException.
Constructors
| Name | Description |
|---|---|
| ContractLocalizedTextProvider(ContractLocalizedTextProvider) | Initializes a new instance of the ContractLocalizedTextProvider class. |
Fields
| Name | Description |
|---|---|
| CreditCardErrorMessage | The identifier of the error message shown when the CreditCardAttribute constraint is violated. |
| EmailAddressErrorMessage | The identifier of the error message shown when the EmailAddressAttribute constraint is violated. |
| EnumDataTypeErrorMessage | The identifier of the error message shown when the EnumDataTypeAttribute constraint is violated. |
| GreaterThanErrorMessage | The identifier of the error message shown when the GreaterThanAttribute constraint is violated. |
| LessThanErrorMessage | The identifier of the error message shown when the LessThanAttribute constraint is violated. |
| LocationContractErrorMessage | The identifier of the error message shown when the LocationContractAttribute constraint is violated. |
| NotEmptyErrorMessage | The identifier of the error message shown when the NotEmptyAttribute constraint is violated. |
| NotNullErrorMessage | The identifier of the error message shown when the NotNullAttribute constraint is violated. |
| PhoneErrorMessage | The identifier of the error message shown when the PhoneAttribute constraint is violated. |
| RangeErrorMessage | The identifier of the error message shown when the RangeAttribute constraint is violated. |
| RegularExpressionErrorMessage | The identifier of the error message shown when the RegularExpressionAttribute constraint is violated. |
| RequiredErrorMessage | The identifier of the error message shown when the RequiredAttribute constraint is violated. |
| StrictRangeErrorMessage | The identifier of the error message shown when the StrictRangeAttribute constraint is violated. |
| StrictlyGreaterThanErrorMessage | The identifier of the error message shown when the StrictlyGreaterThanAttribute constraint is violated. |
| StrictlyLessThanErrorMessage | The identifier of the error message shown when the StrictlyLessThanAttribute constraint is violated. |
| StringLengthMaxErrorMessage | The identifier of the error message shown when the StringLengthAttribute constraint is violated (only the maximum length was specified). |
| StringLengthMinErrorMessage | The identifier of the error message shown when the StringLengthAttribute constraint is violated (only the minimum length was specified). |
| StringLengthRangeErrorMessage | The identifier of the error message shown when the StringLengthAttribute constraint is violated (both the minimum and the maximum length were specified). |
| UrlErrorMessage | The identifier of the error message shown when the UrlAttribute constraint is violated. |
Properties
| Name | Description |
|---|---|
| Current | Gets or sets the current instance of ContractLocalizedTextProvider. |
Methods
| Name | Description |
|---|---|
| GetFormattedMessage(ContractExceptionInfo) | Gets a message template using GetMessage(string) and formats it using the values in |
| GetFormattingStringArguments(object, string, LocationKind, object[]) | Returns an array of arguments that can be passed to the Format(string, params object[]) method. |
| GetMessage(string) | Gets a message declared by the LocalizedTextProvider or by the rest of the responsibility chain, if applicable. |