我的猜测是,它们是恒定的、机器友好的值,可用于唯一标识错误,并可用于获取全球化站点的本地化资源。
protected ValidationError CreateValidationError(
object value, string validationKey, string validationMessage,
params object[] validationMessageParameters)
{
if (validationMessageParameters != null &&
validationMessageParameters.Length > 0)
{
validationMessage = string.Format(
validationMessage, validationMessageParameters);
}
return new ValidationError(
validationKey,
value,
new InvalidOperationException(
localize(validationKey, validationMessage))
);
}
private string localize(string key, string defaultValue)
{
if (phrases == null)
phrases = localizationService.GetTranslations();
Phrase foundPhrase = phrases
.Where(p => p.Key == key && p.Language == site.LanguageDefault)
.FirstOrDefault();
if (foundPhrase != null)
return foundPhrase.Value;
return defaultValue;
}
不过很奇怪。因为异常通常不应该本地化。