本文整理汇总了C#中Validator.AddError方法的典型用法代码示例。如果您正苦于以下问题:C# Validator.AddError方法的具体用法?C# Validator.AddError怎么用?C# Validator.AddError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validator
的用法示例。
在下文中一共展示了Validator.AddError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidatePathCharacters
internal static void ValidatePathCharacters(string folder, string pathPart, Validator validator)
{
var invalidChars = GetInvalidPathChars();
var invalidCharsInPath = folder.Where(invalidChars.Contains);
if (invalidCharsInPath.Any())
{
validator.AddError<InvalidPathException>("The {1} '{2}' in the path '{0}' contains the invalid character '{3}'", pathPart, folder, invalidCharsInPath.First());
}
}
示例2: DriveParser
public DriveParser(string rootedPath, Validator validator)
{
_rootedPath = rootedPath;
_validator = validator;
_isRooted = true;
_driveName = ExtractMappedDrive();
if (_driveName != null) return;
_driveName = ExtractNetworkDrive();
if (_driveName != null) return;
_isRooted = false;
_validator.AddError<NonRootedPathException>("The path '{0}' is not rooted.");
}
示例3: HandleResult
/// <summary>
/// If LastResult is not NoError, this method invokes the appropriate behavior according to how this error handler was created.
/// </summary>
internal void HandleResult( Validator validator, bool errorWouldResultInUnusableReturnValue )
{
if( validationResult.ErrorCondition == ErrorCondition.NoError )
return;
// if there is a custom handler, run it and do nothing else
if( customHandler != null ) {
validator.NoteError();
customHandler( validator, validationResult.ErrorCondition );
return;
}
// build the error message
string message;
if( !customMessages.TryGetValue( validationResult.ErrorCondition, out message ) )
// NOTE: Do we really need custom message, or can the custom handler manage that?
message = validationResult.GetErrorMessage( subject );
validator.AddError( new Error( message, errorWouldResultInUnusableReturnValue ) );
}