本文整理汇总了C#中ValidationResult类的典型用法代码示例。如果您正苦于以下问题:C# ValidationResult类的具体用法?C# ValidationResult怎么用?C# ValidationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationResult类属于命名空间,在下文中一共展示了ValidationResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ShipFit
internal IValidationResult ShipFit(ShipFit shipFit)
{
IValidationResult validationResult = new ValidationResult();
// Check that the ship fit has a valid account id.
if (shipFit.AccountId < 0 || shipFit.AccountId > int.MaxValue)
{
validationResult.AddError("AccountId.Range_" + shipFit.ShipFitId.ToString(), "AccountId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the int data type.");
}
// Null checks.
if (shipFit.Notes == null)
{
validationResult.AddError("Notes.Null", "Notes cannot be null.");
}
if (shipFit.Name == null)
{
validationResult.AddError("Name.Null", "Name cannot be null.");
}
if (shipFit.Role == null)
{
validationResult.AddError("Role.Null", "Role cannot be null.");
}
return validationResult;
}
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:28,代码来源:ShipFitCheck.cs
示例2: When_passed_multiple_errors_Should_aggregate_the_error_messages
public void When_passed_multiple_errors_Should_aggregate_the_error_messages()
{
var result = new ValidationResult();
result.AddError<object>(o => o.GetType(), "foo");
result.AddError<object>(o => o.GetType(), "bar");
result.GetAllErrors().Count.ShouldEqual(1);
}
开发者ID:shawnewallace,项目名称:Griz,代码行数:7,代码来源:ValidationResultTester.cs
示例3: Passing_filled_broken_rules_should_create_invalid_instance
public void Passing_filled_broken_rules_should_create_invalid_instance()
{
var result = new ValidationResult(new List<BrokenRule> { new BrokenRule(null, null, "", "", null) });
Assert.That(result.IsValid, Is.False);
Assert.That(result.BrokenRules.Count, Is.EqualTo(1));
}
开发者ID:modulexcite,项目名称:nValid,代码行数:7,代码来源:ValidationResultTests.cs
示例4: ApiKey
internal IValidationResult ApiKey(IEveDataApiKey apiKeyInfo)
{
IValidationResult validationResult = new ValidationResult();
// Define the bitwise masks for both character and corporation api keys.
const int charContractMask = 67108864;
const int corpContractMask = 8388608;
int checkResult = 0;
// Perform a bitwise AND to determine if contract access is available on the api key.
if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account)
{
checkResult = apiKeyInfo.AccessMask & charContractMask;
if (checkResult == 0)
{
validationResult.AddError("ApiKey.AccessMask", "A character api key must have 'Contracts' access enabled.");
}
}
else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation)
{
checkResult = apiKeyInfo.AccessMask & corpContractMask;
if (checkResult == 0)
{
validationResult.AddError("ApiKey.AccessMask", "A corporation api key must have 'Contracts' access enabled.");
}
}
return validationResult;
}
开发者ID:jameswlong,项目名称:doctrineships,代码行数:31,代码来源:SalesAgentCheck.cs
示例5: Interpret
public static ValidationResult Interpret(
this IEnumerable<IInterpreter> interpreters,
string validationGroup,
Exception exception
)
{
if (null == interpreters)
return null;
if (null == exception)
throw new ArgumentNullException("exception");
var r = new ValidationResult()
{
Exception = exception,
Message = exception.Message,
ValidationGroup = validationGroup
};
foreach (var i in interpreters)
{
if (null == i)
continue;
XElement furtherInformation = null;
string updatedMessage = String.Empty;
if (
i.Interpret(exception, out furtherInformation, ref updatedMessage) == InterpretationStatus.Interpreted
)
{
r.FurtherInformation = furtherInformation;
if(false == String.IsNullOrWhiteSpace(updatedMessage))
r.Message = updatedMessage;
return r;
}
}
return r;
}
开发者ID:BarbaraHarris,项目名称:xcricap-validator,代码行数:34,代码来源:IEnumerableInterpreterExtensionMethods.cs
示例6: Evaluate
/// <summary>
/// Evaluates the rule for the given request. The <b>RegexRule</b> applies its
/// regular expression pattern to its specified field in the given request.
/// </summary>
/// <param name="request">The <b>MvcRequest</b> to evaluate the rule for.</param>
/// <returns>A <b>ValidationResult</b> indicating the result of evaluating the
/// rule and any validation errors that occurred.</returns>
public override ValidationResult Evaluate(
MvcRequest request)
{
ValidationResult result = new ValidationResult {
Passed = false
};
string fieldVal = request[Field.EvaluatePropertyValue()];
// TODO: what if fieldVal is null?? is it valid or not??
// if the field value is null and the check is not explicitly for null,
// add the error
if (fieldVal == null) {
if (this.Pattern == NULL_PATTERN) {
result.Passed = true;
} else {
result.AddError(Field, ErrorId);
}
} else {
bool passed = Regex.IsMatch(fieldVal, this.Pattern);
if (passed) {
result.Passed = true;
} else {
result.AddError(Field, ErrorId);
}
}
return result;
}
开发者ID:rogue-bit,项目名称:Triton-Framework,代码行数:37,代码来源:RegexRule.cs
示例7: ConvertToContractRequiresFix
public ConvertToContractRequiresFix(ValidationResult currentStatement, ValidatedContractBlock validatedContractBlock)
: base(currentStatement, validatedContractBlock)
{
// TODO: refactoring required!! Not clear logic
_precondition =
ContractsEx.Assertions.ContractStatementFactory.TryCreatePrecondition(currentStatement.Statement);
}
开发者ID:remyblok,项目名称:ReSharperContractExtensions,代码行数:7,代码来源:MalformedContractFix.cs
示例8: Validate
public IValidationResult[] Validate()
{
ValidationResult result = new ValidationResult("inlineBinaryContent");
result.Passed = true;
if (iCalendar != null)
{
foreach (UniqueComponent uc in iCalendar.UniqueComponents)
{
if (uc.Attach != null)
{
foreach (Binary b in uc.Attach)
{
// Inline binary content (i.e. BASE64-encoded attachments) are not
// recommended, and should only be used when absolutely necessary.
if (string.Equals(b.Encoding, "BASE64", StringComparison.InvariantCultureIgnoreCase))
{
result.Passed = false;
result.Errors = new IValidationError[]
{
new ValidationErrorWithLookup("inlineBinaryContentError", ValidationErrorType.Warning, false)
};
}
}
if (result.Passed != null)
break;
}
}
}
return new IValidationResult[] { result };
}
开发者ID:xxjeng,项目名称:nuxleus,代码行数:33,代码来源:InlineBinaryContentValidator.cs
示例9: Can_construct_get_and_set_ErrorMessage
public static void Can_construct_get_and_set_ErrorMessage()
{
var validationResult = new ValidationResult("SomeErrorMessage");
Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage);
validationResult.ErrorMessage = "SomeOtherErrorMessage";
Assert.Equal("SomeOtherErrorMessage", validationResult.ErrorMessage);
}
开发者ID:geoffkizer,项目名称:corefx,代码行数:7,代码来源:ValidationResultTests.cs
示例10: Run
public IValidationResult Run(MappingSet set)
{
IValidationResult result = new ValidationResult(this);
DatabaseProcessor proc = new DatabaseProcessor();
var mergeResults = proc.MergeDatabases(_realDatabase, set.Database);
if (mergeResults.AnyChanges)
{
foreach (TableAdditionOperation tableOp in mergeResults.TableOperations.OfType<TableAdditionOperation>())
{
// Additions show things that are in the generated database schema and not in the real one.
result.Issues.Add(new ValidationIssue("Table exists in your NHibernate mapping files but not in your database",
tableOp.Object, ValidationErrorLevel.Warning));
}
foreach (ColumnAdditionOperation columnOp in mergeResults.ColumnOperations.OfType<ColumnAdditionOperation>())
{
result.Issues.Add(new ValidationIssue("Column exists in your NHibernate mapping files but not in your database",
columnOp.Object, ValidationErrorLevel.Warning));
}
}
return result;
}
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:25,代码来源:CheckSchemaAgainstRealDatabaseRule.cs
示例11: ValidationResult_HasValid_Defaults
public void ValidationResult_HasValid_Defaults()
{
var result = new ValidationResult();
Assert.IsTrue(result.IsSuccessful);
Assert.IsNotNull(result.Failures);
}
开发者ID:bashwork,项目名称:common,代码行数:7,代码来源:ValidationResultTests.cs
示例12: ValidationResult_Ctors
public void ValidationResult_Ctors() {
ValidationResult result = new ValidationResult(null);
Assert.IsNull(result.ErrorMessage);
Assert.IsTrue(!result.MemberNames.Any());
result = new ValidationResult(string.Empty);
Assert.AreEqual(string.Empty, result.ErrorMessage);
Assert.IsTrue(!result.MemberNames.Any());
result = new ValidationResult("stuff");
Assert.AreEqual("stuff", result.ErrorMessage);
Assert.IsTrue(!result.MemberNames.Any());
result = new ValidationResult("stuff", new string[] { "m1", "m2" });
Assert.AreEqual("stuff", result.ErrorMessage);
IEnumerable<string> memberNames = result.MemberNames;
Assert.AreEqual(2, memberNames.Count());
Assert.IsTrue(memberNames.Contains("m1"));
Assert.IsTrue(memberNames.Contains("m2"));
#if !SILVERLIGHT
ValidationResult original = new ValidationResult("error", new string[] { "a", "b" });
result = new DerivedValidationResult(original);
Assert.AreEqual("error", result.ErrorMessage);
CollectionAssert.AreEquivalent(new string[] { "a", "b" }, result.MemberNames.ToList());
ExceptionHelper.ExpectArgumentNullException(delegate() {
new DerivedValidationResult(null);
}, "validationResult");
#endif
}
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:31,代码来源:ValidationResultTest.cs
示例13: ContainsEqualValidationResult
/// <summary>
/// Determines whether the collection contains an equivalent ValidationResult
/// </summary>
/// <param name="collection">ValidationResults to search through</param>
/// <param name="target">ValidationResult to search for</param>
/// <returns></returns>
public static bool ContainsEqualValidationResult(this ICollection<ValidationResult> collection, ValidationResult target)
{
foreach (ValidationResult oldValidationResult in collection)
{
if (oldValidationResult.ErrorMessage == target.ErrorMessage)
{
bool movedOld = true;
bool movedTarget = true;
IEnumerator<string> oldEnumerator = oldValidationResult.MemberNames.GetEnumerator();
IEnumerator<string> targetEnumerator = target.MemberNames.GetEnumerator();
while (movedOld && movedTarget)
{
movedOld = oldEnumerator.MoveNext();
movedTarget = targetEnumerator.MoveNext();
if (!movedOld && !movedTarget)
{
return true;
}
if (movedOld != movedTarget || oldEnumerator.Current != targetEnumerator.Current)
{
break;
}
}
}
}
return false;
}
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:34,代码来源:ValidationUtil.cs
示例14: AddIfNew
/// <summary>
/// Adds a new ValidationResult to the collection if an equivalent does not exist.
/// </summary>
/// <param name="collection">ValidationResults to search through</param>
/// <param name="value">ValidationResult to add</param>
public static void AddIfNew(this ICollection<ValidationResult> collection, ValidationResult value)
{
if (!collection.ContainsEqualValidationResult(value))
{
collection.Add(value);
}
}
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:12,代码来源:ValidationUtil.cs
示例15: ShowResult
public void ShowResult(IValidationResult Result)
{
if (Result == null)
Result = new ValidationResult();
int c = 0;
c = Result.Count(r => r.FromRule is IcDphValidator); SetCount(lblpIcDph, c);
c = Result.Count(r => r.FromRule is KvKindValidator); SetCount(lblpDruh, c);
c = Result.Count(r => r.FromRule is PeriodValidator || r.FromRule is YearValidator); SetCount(lblpObdobie, c);
c = Result.Count(r => r.FromRule is NameValidator); SetCount(lblpNazov, c);
c = Result.Count(r => r.FromRule is StateValidator); SetCount(lblpStat, c);
c = Result.Count(r => r.FromRule is CityValidator); SetCount(lblpObec, c);
c = Result.Count(r => r.FromRule is BlackListValidator); SetCount(lblpBlacklist, c);
c = Result.Count(r => r.FromRule is TaxPayerValidator); SetCount(lblpTaxpayers, c);
c = Result.Count(r => r.FromRule is CorrectionValidator); SetCount(lblpKodopravy, c);
c = Result.Count(r => r.FromRule is GoodsValidator); SetCount(lblpTovary, c);
c = Result.Count(r => r.FromRule is TaxRateValidator || r.FromRule is ItemTaxValidator); SetCount(lblpTaxes, c);
c = Result.Count(r => r.ProblemObject is A1); SetCount(lblpA1, c);
c = Result.Count(r => r.ProblemObject is A2); SetCount(lblpA2, c);
c = Result.Count(r => r.ProblemObject is B1); SetCount(lblpB1, c);
c = Result.Count(r => r.ProblemObject is B2); SetCount(lblpB2, c);
c = Result.Count(r => r.ProblemObject is B3); SetCount(lblpB3, c);
c = Result.Count(r => r.ProblemObject is C1); SetCount(lblpC1, c);
c = Result.Count(r => r.ProblemObject is C2); SetCount(lblpC2, c);
c = Result.Count(r => r.ProblemObject is D1); SetCount(lblpD1, c);
c = Result.Count(r => r.ProblemObject is D2); SetCount(lblpD2, c);
}
开发者ID:mkoscak,项目名称:kv-validator,代码行数:28,代码来源:CtrlValidationResult.cs
示例16: Ctor_ValidationResult_ReturnsClone
public void Ctor_ValidationResult_ReturnsClone()
{
ValidationResult validationResult = new ValidationResult("ErrorMessage", new string[] { "Member1", "Member2" });
ValidationResultSubClass createdValidationResult = new ValidationResultSubClass(validationResult);
Assert.Equal(validationResult.ErrorMessage, createdValidationResult.ErrorMessage);
Assert.Equal(validationResult.MemberNames, createdValidationResult.MemberNames);
}
开发者ID:geoffkizer,项目名称:corefx,代码行数:7,代码来源:ValidationResultTests.cs
示例17: ShowValidationResult
public void ShowValidationResult(ValidationResult validationResult)
{
if (!validationResult.IsValid)
{
ShowErrors(validationResult);
}
}
开发者ID:VasiliBaranov,项目名称:navigation-assistant,代码行数:7,代码来源:SettingsWindow.xaml.cs
示例18: Run
public IValidationResult Run(MappingSet set)
{
ValidationResult result = new ValidationResult(this);
if (set.EntitySet == null)
{
result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set, ValidationErrorLevel.Warning));
return result;
}
if (set.EntitySet.IsEmpty)
{
result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set.EntitySet, ValidationErrorLevel.Warning));
return result;
}
var inheritedEntities = set.EntitySet.Entities.Where(e => e.Parent != null);
//foreach (var childEntity in inheritedEntities)
//{
// var parent = childEntity.Parent;
// foreach (Property property in parent.Key.Properties.Distinct(p => p.Name))
// if (childEntity.ConcreteProperties.Any(p => p.Name == property.Name) == false && EntityImpl.DetermineInheritanceTypeWithParent(childEntity) != EntityImpl.InheritanceType.TablePerClassHierarchy)
// result.Issues.Add(new ValidationIssue(string.Format("Key Property {0} is missing from child Entity named {1}", property.Name, childEntity.Name), childEntity, ValidationErrorLevel.Error));
//}
return result;
}
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:26,代码来源:CheckEntityInheritanceForTablePerSubclassRule.cs
示例19: ConvertValidationResultToModelValidationResults
protected virtual IEnumerable<ModelValidationResult> ConvertValidationResultToModelValidationResults(ValidationResult result)
{
return result.Errors.Select(x => new ModelValidationResult {
MemberName = x.PropertyName,
Message = x.ErrorMessage
});
}
开发者ID:rsmolnikov,项目名称:FluentValidation,代码行数:7,代码来源:FluentValidationModelValidator.cs
示例20: Validate
public ValidationResult Validate(IEnumerable<string> userAssemblies, params object[] options)
{
string arguments = this.BuildGendarmeCommandLineArguments(userAssemblies);
ValidationResult validationResult = new ValidationResult()
{
Success = true,
Rule = (IValidationRule) this,
CompilerMessages = (IEnumerable<CompilerMessage>) null
};
try
{
validationResult.Success = GendarmeValidationRule.StartManagedProgram(this._gendarmeExePath, arguments, (CompilerOutputParserBase) new GendarmeOutputParser(), ref validationResult.CompilerMessages);
}
catch (Exception ex)
{
validationResult.Success = false;
// ISSUE: explicit reference operation
// ISSUE: explicit reference operation
(^@validationResult).CompilerMessages = (IEnumerable<CompilerMessage>) new CompilerMessage[1]
{
new CompilerMessage()
{
file = "Exception",
message = ex.Message,
line = 0,
column = 0,
type = CompilerMessageType.Error
}
};
}
return validationResult;
}
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:32,代码来源:GendarmeValidationRule.cs
注:本文中的ValidationResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论