当前位置: 首页>>代码示例>>C#>>正文


C# ValidationErrorCollection.Add方法代码示例

本文整理汇总了C#中ValidationErrorCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrorCollection.Add方法的具体用法?C# ValidationErrorCollection.Add怎么用?C# ValidationErrorCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ValidationErrorCollection的用法示例。


在下文中一共展示了ValidationErrorCollection.Add方法的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);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:CorrelationSetsValidator.cs

示例2: 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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:ListenValidator.cs

示例3: Validate

        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));

            StateActivity state = obj as StateActivity;
            if (state == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj");

            // First we validate contaiment
            if (state.Parent != null)
            {
                if (StateMachineHelpers.IsStateMachine(state))
                {
                    validationErrors.Add(new ValidationError(SR.GetError_StateMachineWorkflowMustBeARootActivity(), ErrorNumbers.Error_StateMachineWorkflowMustBeARootActivity));
                    return validationErrors;
                }
                else
                {
                    // Make sure that a State is always contained in
                    // another State or StateMachineWorkflow. State machine
                    // within a sequential workflow is not supported
                    if (!(state.Parent is StateActivity))
                    {
                        validationErrors.Add(new ValidationError(SR.GetError_InvalidStateActivityParent(), ErrorNumbers.Error_InvalidStateActivityParent));
                        return validationErrors;
                    }
                }
            }

            if (state.Parent == null && !StateMachineHelpers.IsStateMachine(state))
            {
                ValidateCustomStateActivity(state, validationErrors);
            }

            if (StateMachineHelpers.IsLeafState(state))
            {
                ValidateLeafState(state, validationErrors);
            }
            else if (StateMachineHelpers.IsRootState(state))
            {
                ValidateRootState(state, validationErrors);
            }
            else
            {
                ValidateState(state, validationErrors);
            }

            ValidateEventDrivenActivities(state, validationErrors);

            return validationErrors;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:51,代码来源:StateValidator.cs

示例4: Validate

        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");

            Activity activity = obj as Activity;
            if (activity == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(Activity).FullName), "obj");

            if (manager.Context == null)
                throw new ArgumentException("manager", SR.GetString(SR.Error_MissingContextProperty));

            manager.Context.Push(activity);

            ValidationErrorCollection errors = new ValidationErrorCollection();
            errors.AddRange(base.Validate(manager, obj));

            if (activity.Parent == null)
            {
                errors.AddRange(ValidationHelpers.ValidateUniqueIdentifiers(activity));

                if (activity.Enabled == false)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_RootIsNotEnabled), ErrorNumbers.Error_RootIsNotEnabled);
                    error.PropertyName = "Enabled";
                    errors.Add(error);
                }
            }

            // validate ID property, only if it is not root activity
            Activity rootActivity = Helpers.GetRootActivity(activity);
            if (activity != rootActivity)
            {
                ValidationError identifierError = ValidationHelpers.ValidateNameProperty("Name", manager, activity.Name);
                if (identifierError != null)
                    errors.Add(identifierError);
            }

            try
            {
                errors.AddRange(ValidateProperties(manager, obj));
            }
            finally
            {
                System.Diagnostics.Debug.Assert(manager.Context.Current == activity, "Unwinding contextStack: the item that is about to be popped is not the one we pushed.");
                manager.Context.Pop();
            }

            return errors;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:50,代码来源:ActivityValidator.cs

示例5: CreateInstance

 protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader)
 {
     if (workflowDefinitionReader == null)
     {
         throw new ArgumentNullException("workflowDefinitionReader");
     }
     Activity activity = null;
     ValidationErrorCollection errors = new ValidationErrorCollection();
     ServiceContainer container = new ServiceContainer();
     ITypeProvider service = base.Runtime.GetService<ITypeProvider>();
     if (service != null)
     {
         container.AddService(typeof(ITypeProvider), service);
     }
     DesignerSerializationManager manager = new DesignerSerializationManager(container);
     try
     {
         using (manager.CreateSession())
         {
             WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager);
             activity = new WorkflowMarkupSerializer().Deserialize(serializationManager, workflowDefinitionReader) as Activity;
             if ((activity != null) && (rulesReader != null))
             {
                 object obj2 = new WorkflowMarkupSerializer().Deserialize(serializationManager, rulesReader);
                 activity.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, obj2);
             }
             foreach (object obj3 in manager.Errors)
             {
                 if (obj3 is WorkflowMarkupSerializationException)
                 {
                     errors.Add(new ValidationError(((WorkflowMarkupSerializationException) obj3).Message, 0x15b));
                 }
                 else
                 {
                     errors.Add(new ValidationError(obj3.ToString(), 0x15b));
                 }
             }
         }
     }
     catch (Exception exception)
     {
         errors.Add(new ValidationError(exception.Message, 0x15b));
     }
     if (errors.HasErrors)
     {
         throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors);
     }
     return activity;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:49,代码来源:DefaultWorkflowLoaderService.cs

示例6: Validate

 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     Activity context = obj as Activity;
     if (context == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj");
     }
     if (manager.Context == null)
     {
         throw new ArgumentException("manager", SR.GetString("Error_MissingContextProperty"));
     }
     manager.Context.Push(context);
     ValidationErrorCollection errors = new ValidationErrorCollection();
     errors.AddRange(base.Validate(manager, obj));
     if (context.Parent == null)
     {
         errors.AddRange(ValidationHelpers.ValidateUniqueIdentifiers(context));
         if (!context.Enabled)
         {
             ValidationError item = new ValidationError(SR.GetString("Error_RootIsNotEnabled"), 0x628) {
                 PropertyName = "Enabled"
             };
             errors.Add(item);
         }
     }
     Activity rootActivity = Helpers.GetRootActivity(context);
     if (context != rootActivity)
     {
         ValidationError error2 = ValidationHelpers.ValidateNameProperty("Name", manager, context.Name);
         if (error2 != null)
         {
             errors.Add(error2);
         }
     }
     try
     {
         errors.AddRange(this.ValidateProperties(manager, obj));
     }
     finally
     {
         manager.Context.Pop();
     }
     return errors;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:48,代码来源:ActivityValidator.cs

示例7: GetErrors

    public static ValidationErrorCollection GetErrors(object instance)
    {
      ValidationErrorCollection errors = new ValidationErrorCollection();
      foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(instance).Cast<PropertyDescriptor>())
      {
        foreach (ValidationAttribute attribute in prop.Attributes.OfType<ValidationAttribute>())
        {
          if (!attribute.IsValid(prop.GetValue(instance)))
          {
            errors.Add(new ValidationError(prop.Name, attribute.FormatErrorMessage(string.Empty), instance));
          } else if (attribute is DataTypeAttribute){
            var dataAttr = (DataTypeAttribute)attribute;

            // validate datetime min, max
            if (dataAttr.DataType == DataType.Date || dataAttr.DataType == DataType.DateTime){
              if (prop.PropertyType == typeof(DateTime) || (prop.PropertyType == typeof(DateTime?) && prop.GetValue(instance) != null)){
                // validate min date
                DateTime value;
                if (prop.PropertyType == typeof(DateTime))
                {
                  value = (DateTime)prop.GetValue(instance);
                }
                else
                {
                  value = ((DateTime?)prop.GetValue(instance)).Value;
                }

                if (value < System.Data.SqlTypes.SqlDateTime.MinValue.Value || value > System.Data.SqlTypes.SqlDateTime.MaxValue.Value)
                {
                  errors.Add(new ValidationError(prop.Name, "Invalid datetime input", instance));
                }
              }
            }
            else if (dataAttr.DataType == DataType.EmailAddress)
            {
              var value = prop.GetValue(instance) as String;

              if (value.Length > 0 && !Regex.Match(value, "^[\\w\\.=-][email protected][\\w\\.-]+\\.[\\w]{2,}$").Success)
              {
                errors.Add(new ValidationError(prop.Name, "Please enter a valid email address", instance));
              }
            }
          }
        }
      }

      return errors;
    }
开发者ID:nahmedsoftsource,项目名称:framework-abdh,代码行数:48,代码来源:DataAnnotationsValidationRunner.cs

示例8: CreateInstance

        // This function will create a new root activity definition tree by deserializing the xoml and the rules file.
        protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader)
        {
            if (workflowDefinitionReader == null)
                throw new ArgumentNullException("workflowDefinitionReader");

            Activity root = null;
            ValidationErrorCollection errors = new ValidationErrorCollection();
            ServiceContainer serviceContainer = new ServiceContainer();
            ITypeProvider typeProvider = this.Runtime.GetService<ITypeProvider>();
            if (typeProvider != null)
                serviceContainer.AddService(typeof(ITypeProvider), typeProvider);

            DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer);
            try
            {
                using (manager.CreateSession())
                {
                    WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                    root = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, workflowDefinitionReader) as Activity;
                    if (root != null && rulesReader != null)
                    {
                        object rules = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, rulesReader);
                        root.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, rules);
                    }

                    foreach (object error in manager.Errors)
                    {
                        if (error is WorkflowMarkupSerializationException)
                            errors.Add(new ValidationError(((WorkflowMarkupSerializationException)error).Message, ErrorNumbers.Error_SerializationError));
                        else
                            errors.Add(new ValidationError(error.ToString(), ErrorNumbers.Error_SerializationError));
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add(new ValidationError(e.Message, ErrorNumbers.Error_SerializationError));
            }

            if (errors.HasErrors)
                throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors);

            return root;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:45,代码来源:DefaultWorkflowLoaderService.cs

示例9: AddPrefix

    /// <summary>
    /// add prefix to error name
    /// </summary>
    /// <param name="errors"></param>
    /// <param name="prefix"></param>
    /// <returns></returns>
    public static ValidationErrorCollection AddPrefix(this ValidationErrorCollection errors, String prefix)
    {
      var ret = new ValidationErrorCollection();

      foreach (var item in errors)
      {
        ret.Add(prefix + item.Key, new ValidationError(prefix + item.Value.PropertyName, item.Value.ErrorMessage, item.Value.SourceObject));
      }

      return ret;
    }
开发者ID:nahmedsoftsource,项目名称:framework-abdh,代码行数:17,代码来源:ValidationErrorCollectionExtension.cs

示例10: Validate

 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));
     StateActivity state = obj as StateActivity;
     if (state == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(StateActivity).FullName }), "obj");
     }
     if (state.Parent != null)
     {
         if (StateMachineHelpers.IsStateMachine(state))
         {
             validationErrors.Add(new ValidationError(SR.GetError_StateMachineWorkflowMustBeARootActivity(), 0x621));
             return validationErrors;
         }
         if (!(state.Parent is StateActivity))
         {
             validationErrors.Add(new ValidationError(SR.GetError_InvalidStateActivityParent(), 0x62b));
             return validationErrors;
         }
     }
     if ((state.Parent == null) && !StateMachineHelpers.IsStateMachine(state))
     {
         ValidateCustomStateActivity(state, validationErrors);
     }
     if (StateMachineHelpers.IsLeafState(state))
     {
         ValidateLeafState(state, validationErrors);
     }
     else if (StateMachineHelpers.IsRootState(state))
     {
         ValidateRootState(state, validationErrors);
     }
     else
     {
         ValidateState(state, validationErrors);
     }
     ValidateEventDrivenActivities(state, validationErrors);
     return validationErrors;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:40,代码来源:StateActivityValidator.cs

示例11: Validate

        /// <summary>
        ///	Overridden to validate the activity properties and populate the error collection.
        /// Only one child activity is allowed.  If multiple acitivties need to be executed,
        /// place them in a sequence or other appropriate composite activities.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));

            ForEach foreachActivity = obj as ForEach;
            if (foreachActivity == null)
                throw new ArgumentException("Validate parameter 'obj' is not a ForEach activity.");

            if (foreachActivity.EnabledActivities.Count > 1)
                validationErrors.Add(new ValidationError("Only one child is allowed in the ForEach activity.", InvalidNumberOfChildren));

            return validationErrors;
        }
开发者ID:haimon74,项目名称:KanNaim,代码行数:21,代码来源:ForEachValidator.cs

示例12: Validate

 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection(base.Validate(manager, obj));
     WhileActivity activity = obj as WhileActivity;
     if (activity == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(WhileActivity).FullName }), "obj");
     }
     if (activity.EnabledActivities.Count != 1)
     {
         errors.Add(new ValidationError(SR.GetString("Error_WhileShouldHaveOneChild"), 0x60b));
     }
     return errors;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:WhileValidator.cs

示例13: Validate

        /// <summary>
        /// Overridden to validate the activity properties and populate the error collection.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
   			ValidationErrorCollection validationErrorCollection = new ValidationErrorCollection(base.Validate(manager, obj));
            FileSystem activity = obj as FileSystem;


            if (activity.Parent != null)
            {
                if (IsPropertyRequired(activity.Command, FileSystem.SourceProperty.Name) && 
                    (activity.Source == null || activity.Source.Length == 0) && activity.GetBinding(FileSystem.SourceProperty) == null)
                    validationErrorCollection.Add(ValidationError.GetNotSetValidationError(FileSystem.SourceProperty.Name));

                if (IsPropertyRequired(activity.Command, FileSystem.DestinationProperty.Name) &&
                    (activity.Destination == null || activity.Destination.Length == 0) && activity.GetBinding(FileSystem.DestinationProperty) == null)
                    validationErrorCollection.Add(ValidationError.GetNotSetValidationError(FileSystem.DestinationProperty.Name));

                if (IsPropertyRequired(activity.Command, FileSystem.SearchPatternProperty.Name) &&
                    (activity.SearchPattern == null || activity.SearchPattern.Length == 0) && activity.GetBinding(FileSystem.SearchPatternProperty) == null)
                    validationErrorCollection.Add(ValidationError.GetNotSetValidationError(FileSystem.SearchPatternProperty.Name));
            }

			return validationErrorCollection;
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:29,代码来源:FileSystemValidator.cs

示例14: Validate

 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection();
     CodeActivity activity = obj as CodeActivity;
     if (activity == null)
     {
         throw new InvalidOperationException();
     }
     if ((activity.GetInvocationList<EventHandler>(CodeActivity.ExecuteCodeEvent).Length == 0) && (activity.GetBinding(CodeActivity.ExecuteCodeEvent) == null))
     {
         Hashtable hashtable = activity.GetValue(WorkflowMarkupSerializer.EventsProperty) as Hashtable;
         if ((hashtable == null) || (hashtable["ExecuteCode"] == null))
         {
             errors.Add(ValidationError.GetNotSetValidationError("ExecuteCode"));
         }
     }
     errors.AddRange(base.Validate(manager, obj));
     return errors;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:CodeActivity.cs

示例15: ValidateSetStateInsideStateInitializationCore

 private void ValidateSetStateInsideStateInitializationCore(CompositeActivity compositeActivity, StateActivity state, ValidationErrorCollection validationErrors)
 {
     foreach (Activity activity in compositeActivity.EnabledActivities)
     {
         CompositeActivity activity2 = activity as CompositeActivity;
         if (activity2 != null)
         {
             this.ValidateSetStateInsideStateInitializationCore(activity2, state, validationErrors);
         }
         else
         {
             SetStateActivity activity3 = activity as SetStateActivity;
             if (((activity3 != null) && !string.IsNullOrEmpty(activity3.TargetStateName)) && activity3.TargetStateName.Equals(state.QualifiedName))
             {
                 validationErrors.Add(new ValidationError(SR.GetError_InvalidTargetStateInStateInitialization(), 0x605));
                 break;
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:StateInitializationValidator.cs


注:本文中的ValidationErrorCollection.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。