Message Template Tokens

Topics: Validation Application Block
Jul 6, 2007 at 9:01 PM
I am unable to find the Message Template Tokens for the various validators in the Enterprise Library Documentation. I know that all validators use tokens {0}, {1} and {2} and additional tokens. Any suggestions as to where I can find the token description in the documentation for the validators?

Jul 10, 2007 at 3:05 PM
Edited Jul 10, 2007 at 3:06 PM
From the 'Understanding Common Validator Properties' article in the docs:

Understanding Message Template Tokens
Custom message templates can contain tokens. The validator replaces these tokens with values before it adds the resulting message to an instance of the ValidationResult class. Tokens are represented by using the strings {0}, {1}, {2}, and so on within the message template strings. All validators provided by the Validation Application Block use the first three tokens {0}, {1}, and {2} for the same purposes. Different validators may also understand additional tokens, beginning with {3}. The following table describes tokens {0}, {1}, and {2}.

Message Template Tokens

This token represents the value of the object that is being validated. While it can be useful to show the original value as a part of the validation message, you must be careful to avoid injection attacks by escaping any characters that can be used to attack the system that conveys the message to the user.

This token represents the key of the object that is being validated. When the validator is attached to a member of a type such as a property or a field, the key is set to the member name. When the validator is attached to an object, the key is null and the token is replaced by an empty string.

This token represents the tag that is specified on the validator instance. If no tag is supplied, the token is replaced by an empty string.

For more information on tokens, see String.Format Method on MSDN.