本文整理汇总了C#中ValidationErrorCollection类的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrorCollection类的具体用法?C# ValidationErrorCollection怎么用?C# ValidationErrorCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationErrorCollection类属于命名空间,在下文中一共展示了ValidationErrorCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillCorrelationAliasAttrs
private static void FillCorrelationAliasAttrs(MemberInfo memberInfo, Hashtable correlationAliasAttrs, ValidationErrorCollection validationErrors)
{
foreach (object obj2 in memberInfo.GetCustomAttributes(typeof(CorrelationAliasAttribute), false))
{
CorrelationAliasAttribute attributeFromObject = Helpers.GetAttributeFromObject<CorrelationAliasAttribute>(obj2);
if (string.IsNullOrEmpty(attributeFromObject.Name) || (attributeFromObject.Name.Trim().Length == 0))
{
ValidationError item = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationAttributeInvalid", new object[] { typeof(CorrelationAliasAttribute).Name, "Name", memberInfo.Name }), 0x150);
item.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name);
validationErrors.Add(item);
}
else if (string.IsNullOrEmpty(attributeFromObject.Path) || (attributeFromObject.Path.Trim().Length == 0))
{
ValidationError error2 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationAttributeInvalid", new object[] { typeof(CorrelationAliasAttribute).Name, "Path", memberInfo.Name }), 0x150);
error2.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name);
validationErrors.Add(error2);
}
else if (correlationAliasAttrs.Contains(attributeFromObject.Name))
{
ValidationError error3 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_DuplicateCorrelationAttribute", new object[] { typeof(CorrelationAliasAttribute).Name, attributeFromObject.Name, memberInfo.Name }), 0x151);
error3.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name);
validationErrors.Add(error3);
}
else
{
correlationAliasAttrs.Add(attributeFromObject.Name, attributeFromObject);
}
}
}
示例2: RuleValidation
public RuleValidation(Activity activity, ITypeProvider typeProvider, bool checkStaticType)
{
this.errors = new ValidationErrorCollection();
this.typesUsed = new Dictionary<string, Type>(0x10);
this.activeParentNodes = new Stack<CodeExpression>();
this.expressionInfoMap = new Dictionary<CodeExpression, RuleExpressionInfo>();
this.typeRefMap = new Dictionary<CodeTypeReference, Type>();
if (activity == null)
{
throw new ArgumentNullException("activity");
}
if (typeProvider == null)
{
throw new ArgumentNullException("typeProvider");
}
this.thisType = ConditionHelper.GetContextType(typeProvider, activity);
this.typeProvider = typeProvider;
this.checkStaticType = checkStaticType;
if (checkStaticType)
{
this.authorizedTypes = WorkflowCompilationContext.Current.GetAuthorizedTypes();
this.typesUsedAuthorized = new Dictionary<string, Type>();
this.typesUsedAuthorized.Add(voidTypeName, voidType);
}
}
示例3: SetErrors
/// <summary>
/// Inherited from <see cref="IValidationManager"/>.
/// <para>
/// This manager assumes all objects within <paramref name="validationResult"/> are of type <see cref="ValidationResult"/>.
/// </para>
/// <para>
/// This manager assumes all <see cref="ValidationResult"/> objects within <paramref name="validationResult"/> that
/// have an empty <see cref="P:ValidationResult.MemberNames"/> collection are top level or class level issues.
/// </para>
/// </summary>
/// <param name="errorCollection">A <see cref="ValidationErrorCollection"/> that houses the validation results.</param>
/// <param name="validationResult">A <see cref="IEnumerable{T}"/> that represents the collection of validation issues that need to be applied to <paramref name="errorCollection"/>.</param>
public virtual void SetErrors(ValidationErrorCollection errorCollection, IEnumerable<object> validationResult)
{
lock (_syncObject)
{
IEnumerable<ValidationResult> vResults = validationResult.Cast<ValidationResult>();
var results =
(from g in
(from tuple in
(from r in vResults
from name in r.MemberNames
select new Tuple<string, ValidationResult>(name, r))
group tuple by tuple.Item1)
select new Tuple<string, IEnumerable<ValidationResult>>(g.Key, g.Select(a => a.Item2))).ToArray();
if (vResults.Any(a => a.MemberNames.Count() == 0))
{
Tuple<string, IEnumerable<ValidationResult>> newTuple = new Tuple<string, IEnumerable<ValidationResult>>(string.Empty, from vr in vResults
where vr.MemberNames.Count() == 0
select vr);
results = results.Concat(new Tuple<string, IEnumerable<ValidationResult>>[] { newTuple }).ToArray();
}
errorCollection.Clear();
foreach (Tuple<string, IEnumerable<ValidationResult>> item in results)
errorCollection.SetErrors(item.Item1, item.Item2.Cast<object>());
}
}
示例4: ValidateCustomStateActivity
private static void ValidateCustomStateActivity(StateActivity state, ValidationErrorCollection validationErrors)
{
if (state.Activities.Count > 0)
{
validationErrors.Add(new ValidationError(SR.GetError_BlackBoxCustomStateNotSupported(), ErrorNumbers.Error_BlackBoxCustomStateNotSupported));
}
}
示例5: MinLengthViolationTest
public void MinLengthViolationTest()
{
MinimumLengthAttribute attribute = new MinimumLengthAttribute(8);
ValidationErrorCollection errors = new ValidationErrorCollection();
attribute.Validate(minLengthNode, valueInfo1, errors);
Assert.AreEqual(1, errors.Count);
}
示例6: Validate
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
{
ValidationErrorCollection errors = new ValidationErrorCollection(base.Validate(manager, obj));
ListenActivity activity = obj as ListenActivity;
if (activity == null)
{
throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ListenActivity).FullName }), "obj");
}
if (activity.EnabledActivities.Count < 2)
{
errors.Add(new ValidationError(SR.GetString("Error_ListenLessThanTwoChildren"), 0x513));
}
bool flag = false;
foreach (Activity activity2 in activity.EnabledActivities)
{
if (!(activity2 is EventDrivenActivity))
{
flag = true;
}
}
if (flag)
{
errors.Add(new ValidationError(SR.GetString("Error_ListenNotAllEventDriven"), 0x514));
}
return errors;
}
示例7: RequiredNotThereTest
public void RequiredNotThereTest()
{
RequiredAttribute attribute = new RequiredAttribute();
ValidationErrorCollection errors = new ValidationErrorCollection();
attribute.Validate(requiredNode, valueInfo1, errors);
Assert.AreEqual(1, errors.Count);
}
示例8: SetValidationErrors
internal void SetValidationErrors(ValidationErrorCollection errors)
{
foreach(ValidationError error in errors)
{
validationErrorsBox.Items.Add(error);
}
}
示例9: ValidateProperties
public virtual ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj)
{
if (manager == null)
{
throw new ArgumentNullException("manager");
}
if (obj == null)
{
throw new ArgumentNullException("obj");
}
ValidationErrorCollection errors = new ValidationErrorCollection();
Activity activity = manager.Context[typeof(Activity)] as Activity;
Walker walker = new Walker(true);
walker.FoundProperty += delegate (Walker w, WalkerEventArgs args) {
if ((args.CurrentProperty != null) && (DependencyProperty.FromName(args.CurrentProperty.Name, args.CurrentProperty.DeclaringType) == null))
{
object[] customAttributes = args.CurrentProperty.GetCustomAttributes(typeof(ValidationOptionAttribute), true);
if (((customAttributes.Length > 0) ? ((ValidationOptionAttribute) customAttributes[0]).ValidationOption : ValidationOption.Optional) != ValidationOption.None)
{
errors.AddRange(this.ValidateProperty(args.CurrentProperty, args.CurrentPropertyOwner, args.CurrentValue, manager));
args.Action = WalkerAction.Skip;
}
}
};
walker.WalkProperties(activity, obj);
return errors;
}
示例10: MaxLengthViolationTest
public void MaxLengthViolationTest()
{
MaximumLengthAttribute attribute = new MaximumLengthAttribute(3);
maxLengthNode.Value1 = "aaaa";
ValidationErrorCollection errors = new ValidationErrorCollection();
attribute.Validate(maxLengthNode, valueInfo1, errors);
Assert.AreEqual(1, errors.Count);
}
示例11: CharOutOfRangeTest
public void CharOutOfRangeTest()
{
AssertRangeAttribute assertRange = new AssertRangeAttribute('a', RangeBoundaryType.Inclusive, 'd', RangeBoundaryType.Exclusive);
rangeClass.CharValue = 'd';
ValidationErrorCollection errors = new ValidationErrorCollection();
assertRange.Validate(rangeClass, charInfo, errors);
Assert.AreEqual(1, errors.Count);
}
示例12: MinLengthTest
public void MinLengthTest()
{
MinimumLengthAttribute attribute = new MinimumLengthAttribute(8);
minLengthNode.Value2 = "MyTestPassword";
ValidationErrorCollection errors = new ValidationErrorCollection();
attribute.Validate(minLengthNode, valueInfo2, errors);
Assert.AreEqual(0, errors.Count);
}
示例13: ValidTypeProducesNoErrors
public void ValidTypeProducesNoErrors()
{
TypeValidationAttribute attribute = new TypeValidationAttribute();
ValidationErrorCollection errors = new ValidationErrorCollection();
typeNode.TypeName = GetType().AssemblyQualifiedName;
attribute.Validate(typeNode, valueInfo1, errors);
Assert.AreEqual(0, errors.Count);
}
示例14: InvalidTypeProducesAnError
public void InvalidTypeProducesAnError()
{
TypeValidationAttribute attribute = new TypeValidationAttribute();
typeNode.TypeName = "MyTest";
ValidationErrorCollection errors = new ValidationErrorCollection();
attribute.Validate(typeNode, valueInfo1, errors);
Assert.AreEqual(1, errors.Count);
}
示例15: FloatInRangeTest
public void FloatInRangeTest()
{
AssertRangeAttribute assertRange = new AssertRangeAttribute(3f, RangeBoundaryType.Inclusive, 43f, RangeBoundaryType.Exclusive);
rangeClass.FloatValue = 25;
ValidationErrorCollection errors = new ValidationErrorCollection();
assertRange.Validate(rangeClass, floatInfo, errors);
Assert.AreEqual(0, errors.Count);
}