本文整理汇总了C#中Catel.Data.ValidationContext.AddFieldValidationResult方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext.AddFieldValidationResult方法的具体用法?C# ValidationContext.AddFieldValidationResult怎么用?C# ValidationContext.AddFieldValidationResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Catel.Data.ValidationContext
的用法示例。
在下文中一共展示了ValidationContext.AddFieldValidationResult方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
//.........这里部分代码省略.........
#region Fields
if (validator != null)
{
validator.BeforeValidateFields(this, validationContext.GetFieldValidations());
}
OnValidatingFields(validationContext);
if (validator != null)
{
validator.ValidateFields(this, fieldValidationResults);
}
#if !WINDOWS_PHONE && !NETFX_CORE && !PCL && !NET35
// Support annotation validation
fieldValidationResults.AddRange(from fieldAnnotationValidation in _dataAnnotationValidationResults
where !string.IsNullOrEmpty(fieldAnnotationValidation.Value)
select (IFieldValidationResult)FieldValidationResult.CreateError(fieldAnnotationValidation.Key, fieldAnnotationValidation.Value));
#endif
ValidateFields(fieldValidationResults);
OnValidatedFields(validationContext);
if (validator != null)
{
validator.AfterValidateFields(this, fieldValidationResults);
}
// As the last step, sync the field validation results with the context
foreach (var fieldValidationResult in fieldValidationResults)
{
validationContext.AddFieldValidationResult(fieldValidationResult);
}
#endregion
#region Business rules
if (validator != null)
{
validator.BeforeValidateBusinessRules(this, validationContext.GetBusinessRuleValidations());
}
OnValidatingBusinessRules(validationContext);
if (validator != null)
{
validator.ValidateBusinessRules(this, businessRuleValidationResults);
}
ValidateBusinessRules(businessRuleValidationResults);
OnValidatedBusinessRules(validationContext);
if (validator != null)
{
validator.AfterValidateBusinessRules(this, businessRuleValidationResults);
}
// As the last step, sync the field validation results with the context
foreach (var businessRuleValidationResult in businessRuleValidationResults)
{
validationContext.AddBusinessRuleValidationResult(businessRuleValidationResult);
}
#endregion
示例2: CorrectlyHandlesRemovalOfExistingValidationResult
public void CorrectlyHandlesRemovalOfExistingValidationResult()
{
var validationContext = new ValidationContext();
var fieldValidation = FieldValidationResult.CreateError("MyProperty", "MyError");
validationContext.AddFieldValidationResult(fieldValidation);
Assert.AreEqual(1, validationContext.GetFieldValidationCount());
validationContext.RemoveFieldValidationResult(fieldValidation);
Assert.AreEqual(0, validationContext.GetFieldValidationCount());
}
示例3: ThrowsArgumentNullExceptionForNullValidationResult
public void ThrowsArgumentNullExceptionForNullValidationResult()
{
var validationContext = new ValidationContext();
ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => validationContext.AddFieldValidationResult(null));
}
示例4: AddsMultipleValidationResultsForField
public void AddsMultipleValidationResultsForField()
{
var validationContext = new ValidationContext();
var fieldValidation = FieldValidationResult.CreateError("MyProperty", "MyError");
validationContext.AddFieldValidationResult(fieldValidation);
Assert.AreEqual(1, validationContext.GetFieldValidationCount());
validationContext.AddFieldValidationResult(fieldValidation);
Assert.AreEqual(2, validationContext.GetFieldValidationCount());
}
示例5: Parse
//.........这里部分代码省略.........
Log.Debug("Parsing command line");
for (var i = 0; i < commandLineArguments.Count; i++)
{
var commandLineArgument = commandLineArguments[i];
try
{
// Allow the first one to be a non-switch
if (i == 0)
{
if (!commandLineArguments[i].IsSwitch())
{
var emptyOptionDefinition = (from x in optionDefinitions
where !x.HasSwitch()
select x).FirstOrDefault();
if (emptyOptionDefinition == null)
{
var message = string.Format(_languageService.GetString("CommandLine_CannotParseNoEmptySwitch"), commandLineArgument);
Log.Error(message);
validationContext.AddBusinessRuleValidationResult(BusinessRuleValidationResult.CreateError(message));
continue;
}
UpdateContext(targetContext, emptyOptionDefinition, commandLineArgument);
handledOptions.Add(emptyOptionDefinition.ShortName);
continue;
}
}
if (!commandLineArgument.IsSwitch())
{
var message = string.Format(_languageService.GetString("CommandLine_CannotParseNoSwitch"), commandLineArgument);
Log.Warning(message);
validationContext.AddBusinessRuleValidationResult(BusinessRuleValidationResult.CreateWarning(message));
continue;
}
var optionDefinition = (from x in optionDefinitions
where x.IsSwitch(commandLineArgument)
select x).FirstOrDefault();
if (optionDefinition == null)
{
var message = string.Format(_languageService.GetString("CommandLine_CannotParseSwitchNotRecognized"), commandLineArgument);
Log.Warning(message);
validationContext.AddBusinessRuleValidationResult(BusinessRuleValidationResult.CreateWarning(message));
continue;
}
var value = string.Empty;
if (!optionDefinition.AcceptsValue)
{
// Assume boolean switch
value = "true";
}
else
{
if (commandLineArguments.Count <= i + 1)
{
var message = string.Format(_languageService.GetString("CommandLine_CannotParseValueMissing"), commandLineArgument);
Log.Warning(message);
validationContext.AddBusinessRuleValidationResult(BusinessRuleValidationResult.CreateWarning(message));
continue;
}
value = commandLineArguments[++i];
}
UpdateContext(targetContext, optionDefinition, value);
handledOptions.Add(optionDefinition.ShortName);
}
catch (Exception ex)
{
validationContext.AddBusinessRuleValidationResult(BusinessRuleValidationResult.CreateError(_languageService.GetString("CommandLine_CannotParseExceptionOccurred"), commandLineArgument, ex.Message));
}
}
Log.Debug("Checking if all required options are specified");
foreach (var optionDefinition in optionDefinitions)
{
if (optionDefinition.IsMandatory)
{
if (!handledOptions.Contains(optionDefinition.ShortName))
{
var message = string.Format(_languageService.GetString("CommandLine_RequiredSwitchNotSpecified"), optionDefinition);
Log.Error(message);
validationContext.AddFieldValidationResult(FieldValidationResult.CreateError(optionDefinition.GetSwitchDisplay(), message));
}
}
}
Log.Debug("Finishing the context");
targetContext.Finish();
return validationContext;
}