本文整理汇总了C#中ValidationErrorCollection.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrorCollection.AddRange方法的具体用法?C# ValidationErrorCollection.AddRange怎么用?C# ValidationErrorCollection.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationErrorCollection
的用法示例。
在下文中一共展示了ValidationErrorCollection.AddRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: Validate
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
{
ValidationErrorCollection errors = new ValidationErrorCollection();
errors.AddRange(base.Validate(manager, obj));
CodeCondition condition = obj as CodeCondition;
if (((condition != null) && (condition.GetInvocationList<EventHandler<ConditionalEventArgs>>(CodeCondition.ConditionEvent).Length == 0)) && (condition.GetBinding(CodeCondition.ConditionEvent) == null))
{
Hashtable hashtable = condition.GetValue(WorkflowMarkupSerializer.EventsProperty) as Hashtable;
if ((hashtable != null) && (hashtable["Condition"] != null))
{
return errors;
}
errors.Add(ValidationError.GetNotSetValidationError(base.GetFullPropertyName(manager) + ".Condition"));
}
return errors;
}
示例5: 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;
}
示例6: Validate
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
{
ValidationErrorCollection errors = new ValidationErrorCollection();
CodeActivity code = obj as CodeActivity;
if (code == null)
throw new InvalidOperationException();
// This violates the P || C validation condition, but we are compiling with csc.exe here!
if (code.GetInvocationList<EventHandler>(CodeActivity.ExecuteCodeEvent).Length == 0 &&
code.GetBinding(CodeActivity.ExecuteCodeEvent) == null)
{
Hashtable hashtable = code.GetValue(WorkflowMarkupSerializer.EventsProperty) as Hashtable;
if (hashtable == null || hashtable["ExecuteCode"] == null)
errors.Add(ValidationError.GetNotSetValidationError("ExecuteCode"));
}
errors.AddRange(base.Validate(manager, obj));
return errors;
}
示例7: 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;
// Validate all members that support validations.
Walker walker = new Walker(true);
walker.FoundProperty += delegate(Walker w, WalkerEventArgs args)
{
//If we find dynamic property of the same name then we do not invoke the validator associated with the property
//Attached dependency properties will not be found by FromName().
// args.CurrentProperty can be null if the property is of type IList. The walker would go into each item in the
// list, but we don't need to validate these items.
if (args.CurrentProperty != null)
{
DependencyProperty dependencyProperty = DependencyProperty.FromName(args.CurrentProperty.Name, args.CurrentProperty.DeclaringType);
if (dependencyProperty == null)
{
object[] validationVisibilityAtrributes = args.CurrentProperty.GetCustomAttributes(typeof(ValidationOptionAttribute), true);
ValidationOption validationVisibility = (validationVisibilityAtrributes.Length > 0) ? ((ValidationOptionAttribute)validationVisibilityAtrributes[0]).ValidationOption : ValidationOption.Optional;
if (validationVisibility != ValidationOption.None)
{
errors.AddRange(ValidateProperty(args.CurrentProperty, args.CurrentPropertyOwner, args.CurrentValue, manager));
// don't probe into subproperties as validate object inside the ValidateProperties call does it for us
args.Action = WalkerAction.Skip;
}
}
}
};
walker.WalkProperties(activity, obj);
return errors;
}
示例8: ValidateObject
internal static ValidationErrorCollection ValidateObject(ValidationManager manager, object obj)
{
ValidationErrorCollection errors = new ValidationErrorCollection();
if (obj == null)
return errors;
Type objType = obj.GetType();
if (!objType.IsPrimitive && (objType != typeof(string)))
{
bool removeValidatedObjectCollection = false;
Dictionary<int, object> validatedObjects = manager.Context[typeof(Dictionary<int, object>)] as Dictionary<int, object>;
if (validatedObjects == null)
{
validatedObjects = new Dictionary<int, object>();
manager.Context.Push(validatedObjects);
removeValidatedObjectCollection = true;
}
try
{
if (!validatedObjects.ContainsKey(obj.GetHashCode()))
{
validatedObjects.Add(obj.GetHashCode(), obj);
try
{
Validator[] validators = manager.GetValidators(objType);
foreach (Validator validator in validators)
errors.AddRange(validator.Validate(manager, obj));
}
finally
{
validatedObjects.Remove(obj.GetHashCode());
}
}
}
finally
{
if (removeValidatedObjectCollection)
manager.Context.Pop();
}
}
return errors;
}
示例9: ApplyTo
internal void ApplyTo(Activity activity)
{
if (activity == null)
{
throw new ArgumentNullException("activity");
}
if (activity.Parent != null)
{
throw new ArgumentException(SR.GetString("Error_RootActivityTypeInvalid"), "activity");
}
if (activity.RootActivity == null)
{
throw new InvalidOperationException(SR.GetString("Error_MissingRootActivity"));
}
if (activity.WorkflowCoreRuntime == null)
{
throw new InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"));
}
if (this.saved)
{
throw new InvalidOperationException(SR.GetString("Error_TransactionAlreadyApplied"));
}
if (!CompareWorkflowDefinition(this.originalRootActivity, (Activity) activity.RootActivity.GetValue(Activity.WorkflowDefinitionProperty)))
{
throw new ArgumentException(SR.GetString("Error_WorkflowDefinitionModified"), "activity");
}
this.Save();
IWorkflowCoreRuntime workflowCoreRuntime = activity.WorkflowCoreRuntime;
if (workflowCoreRuntime.CurrentAtomicActivity != null)
{
throw new InvalidOperationException(SR.GetString("Error_InsideAtomicScope"));
}
bool flag = workflowCoreRuntime.SuspendInstance(SR.GetString("SuspendReason_WorkflowChange"));
try
{
List<Activity> list = new List<Activity>();
Queue<Activity> queue = new Queue<Activity>();
queue.Enqueue(workflowCoreRuntime.RootActivity);
while (queue.Count > 0)
{
Activity item = queue.Dequeue();
list.Add(item);
IList<Activity> list2 = (IList<Activity>) item.GetValue(Activity.ActiveExecutionContextsProperty);
if (list2 != null)
{
foreach (Activity activity3 in list2)
{
queue.Enqueue(activity3);
}
}
}
ValidationErrorCollection errors = new ValidationErrorCollection();
foreach (WorkflowChangeAction action in this.modelChangeActions)
{
if (action is ActivityChangeAction)
{
foreach (Activity activity4 in list)
{
if ((action is RemovedActivityAction) && (activity4.DottedPath == ((RemovedActivityAction) action).OriginalRemovedActivity.DottedPath))
{
errors.AddRange(action.ValidateChanges(activity4));
}
if (activity4.TraverseDottedPathFromRoot(((ActivityChangeAction) action).OwnerActivityDottedPath) != null)
{
errors.AddRange(action.ValidateChanges(activity4));
}
}
}
}
if (errors.HasErrors)
{
throw new WorkflowValidationFailedException(SR.GetString("Error_RuntimeValidationFailed"), errors);
}
this.VerifyWorkflowCanBeChanged(workflowCoreRuntime);
workflowCoreRuntime.OnBeforeDynamicChange(this.modelChangeActions);
workflowCoreRuntime.RootActivity.SetValue(Activity.WorkflowDefinitionProperty, this.clonedRootActivity);
foreach (Activity activity5 in list)
{
foreach (WorkflowChangeAction action2 in this.modelChangeActions)
{
if ((action2 is ActivityChangeAction) && (activity5.TraverseDottedPathFromRoot(((ActivityChangeAction) action2).OwnerActivityDottedPath) != null))
{
action2.ApplyTo(activity5);
}
}
Activity activityByName = this.clonedRootActivity.GetActivityByName(activity5.QualifiedName);
if (activityByName != null)
{
activity5.FixUpMetaProperties(activityByName);
}
this.NotifyChangesToChildExecutors(workflowCoreRuntime, activity5, this.modelChangeActions);
this.NotifyChangesCompletedToChildExecutors(workflowCoreRuntime, activity5);
}
workflowCoreRuntime.OnAfterDynamicChange(true, this.modelChangeActions);
}
catch
{
workflowCoreRuntime.OnAfterDynamicChange(false, this.modelChangeActions);
throw;
}
//.........这里部分代码省略.........
示例10: ApplyTo
internal void ApplyTo(Activity activity)
{
if (activity == null)
throw new ArgumentNullException("activity");
if (activity.Parent != null)
throw new ArgumentException(SR.GetString(SR.Error_RootActivityTypeInvalid), "activity");
if (activity.RootActivity == null)
throw new InvalidOperationException(SR.GetString(SR.Error_MissingRootActivity));
if (activity.WorkflowCoreRuntime == null)
throw new InvalidOperationException(SR.GetString(SR.Error_NoRuntimeAvailable));
if (this.saved)
throw new InvalidOperationException(SR.GetString(SR.Error_TransactionAlreadyApplied));
if (!CompareWorkflowDefinition((Activity)this.originalRootActivity, (Activity)activity.RootActivity.GetValue(Activity.WorkflowDefinitionProperty)))
throw new ArgumentException(SR.GetString(SR.Error_WorkflowDefinitionModified), "activity");
this.Save();
// go up in the chain and then apply changes
IWorkflowCoreRuntime workflowCoreRuntime = activity.WorkflowCoreRuntime;
if (workflowCoreRuntime.CurrentAtomicActivity != null)
throw new InvalidOperationException(SR.GetString(SR.Error_InsideAtomicScope));
bool suspended = workflowCoreRuntime.SuspendInstance(SR.GetString(SR.SuspendReason_WorkflowChange));
try
{
// collect all context Activities
List<Activity> contextActivities = new List<Activity>();
Queue<Activity> contextActivitiesQueue = new Queue<Activity>();
contextActivitiesQueue.Enqueue(workflowCoreRuntime.RootActivity);
while (contextActivitiesQueue.Count > 0)
{
Activity contextActivity = contextActivitiesQueue.Dequeue();
contextActivities.Add(contextActivity);
// enqueue child context Activities
IList<Activity> nestedContextActivities = (IList<Activity>)contextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
if (nestedContextActivities != null)
{
foreach (Activity nestedContextActivity in nestedContextActivities)
contextActivitiesQueue.Enqueue(nestedContextActivity);
}
}
// run instance level validations
ValidationErrorCollection validationErrors = new ValidationErrorCollection();
foreach (WorkflowChangeAction changeAction in this.modelChangeActions)
{
if (changeAction is ActivityChangeAction)
{
foreach (Activity contextActivity in contextActivities)
{
// WinOE Bug 16903: Ask the contextActivity itself whether or not it can be removed.
// An activity can not be removed if it's in the executing mode.
if (changeAction is RemovedActivityAction &&
contextActivity.DottedPath == ((RemovedActivityAction)changeAction).OriginalRemovedActivity.DottedPath)
validationErrors.AddRange(changeAction.ValidateChanges(contextActivity));
// Ask the parent context activity whether or not this child activity can be added or removed.
// The call to TraverseDottedPathFromRoot here should return the parent context activity for this change action.
if (contextActivity.TraverseDottedPathFromRoot(((ActivityChangeAction)changeAction).OwnerActivityDottedPath) != null)
validationErrors.AddRange(changeAction.ValidateChanges(contextActivity));
}
}
}
// if errors then return
if (validationErrors.HasErrors)
throw new WorkflowValidationFailedException(SR.GetString(SR.Error_RuntimeValidationFailed), validationErrors);
// verify if workflow can be changed
VerifyWorkflowCanBeChanged(workflowCoreRuntime);
// inform workflow runtime
workflowCoreRuntime.OnBeforeDynamicChange(this.modelChangeActions);
// set the new Workflow Definition
workflowCoreRuntime.RootActivity.SetValue(Activity.WorkflowDefinitionProperty, this.clonedRootActivity);
// apply changes to all context Activities
foreach (Activity contextActivity in contextActivities)
{
// apply change to state reader
foreach (WorkflowChangeAction changeAction in this.modelChangeActions)
{
if (changeAction is ActivityChangeAction)
{
if (contextActivity.TraverseDottedPathFromRoot(((ActivityChangeAction)changeAction).OwnerActivityDottedPath) != null)
{
bool result = changeAction.ApplyTo(contextActivity);
Debug.Assert(result, "ApplyTo failed");
}
}
}
// fixup meta properties and notify changes
// if the context activity is the one that's being removed, we do not fixup the meta properties.
Activity clonedActivity = ((Activity)this.clonedRootActivity).GetActivityByName(contextActivity.QualifiedName);
//.........这里部分代码省略.........
示例11: Validate
internal static ValidationErrorCollection Validate(ValidationManager manager, object obj)
{
object[] attributes;
CorrelationToken correlator;
string qualifiedCorrelationToken;
Activity sourceActivity;
ValidationErrorCollection errors = new ValidationErrorCollection();
Activity activity = obj as Activity;
if (!(activity is CallExternalMethodActivity) && !(activity is HandleExternalEventActivity))
{
throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj");
}
Type interfaceType = (activity is CallExternalMethodActivity) ? ((CallExternalMethodActivity) activity).InterfaceType : ((HandleExternalEventActivity) activity).InterfaceType;
if (interfaceType != null)
{
if (interfaceType.ContainsGenericParameters)
{
ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_GenericMethodsNotSupported"), new object[] { interfaceType.FullName }), 0x155) {
PropertyName = "InterfaceType"
};
errors.Add(item);
return errors;
}
attributes = interfaceType.GetCustomAttributes(typeof(ExternalDataExchangeAttribute), false);
if (attributes.Length == 0)
{
ValidationError error2 = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ExternalDataExchangeException"), new object[] { interfaceType.FullName }), 0x113) {
PropertyName = "InterfaceType"
};
errors.Add(error2);
return errors;
}
if (activity.Site == null)
{
ValidationErrorCollection errors2 = ValidateHostInterface(manager, interfaceType, activity);
if (errors2.Count != 0)
{
errors.AddRange(errors2);
return errors;
}
}
MemberInfo info = null;
if (activity is CallExternalMethodActivity)
{
if ((((CallExternalMethodActivity) activity).MethodName == null) || (((CallExternalMethodActivity) activity).MethodName.Length == 0))
{
return errors;
}
MethodInfo info2 = interfaceType.GetMethod(((CallExternalMethodActivity) activity).MethodName, BindingFlags.Public | BindingFlags.Instance);
if ((info2 == null) || info2.IsSpecialName)
{
errors.Add(new ValidationError(SR.GetString("Error_MissingMethodName", new object[] { activity.Name, ((CallExternalMethodActivity) activity).MethodName }), 0x528));
return errors;
}
if (info2.ContainsGenericParameters)
{
ValidationError error3 = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_GenericMethodsNotSupported"), new object[] { info2.Name }), 0x155) {
PropertyName = "MethodName"
};
errors.Add(error3);
return errors;
}
info = info2;
}
else
{
if ((((HandleExternalEventActivity) activity).EventName == null) || (((HandleExternalEventActivity) activity).EventName.Length == 0))
{
return errors;
}
EventInfo info3 = interfaceType.GetEvent(((HandleExternalEventActivity) activity).EventName, BindingFlags.Public | BindingFlags.Instance);
if (info3 == null)
{
errors.Add(new ValidationError(SR.GetString("Error_MissingEventName", new object[] { activity.Name, ((HandleExternalEventActivity) activity).EventName }), 0x528));
return errors;
}
info = info3;
}
attributes = interfaceType.GetCustomAttributes(typeof(CorrelationProviderAttribute), false);
if (attributes.Length == 0)
{
correlator = activity.GetValue((activity is CallExternalMethodActivity) ? CallExternalMethodActivity.CorrelationTokenProperty : HandleExternalEventActivity.CorrelationTokenProperty) as CorrelationToken;
if (interfaceType.GetCustomAttributes(typeof(CorrelationParameterAttribute), false).Length == 0)
{
if (correlator != null)
{
errors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_CorrelationTokenSpecifiedForUncorrelatedInterface"), new object[] { activity.QualifiedName, interfaceType }), 0x119, false, "CorrelationToken"));
}
return errors;
}
if (activity.Parent == null)
{
return errors;
}
if ((correlator == null) || string.IsNullOrEmpty(correlator.Name))
{
errors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_MissingCorrelationTokenProperty"), new object[] { activity.QualifiedName }), 0x109, false, "CorrelationToken"));
return errors;
}
if (string.IsNullOrEmpty(correlator.OwnerActivityName))
//.........这里部分代码省略.........
示例12: ValidateParameterBinding
private static void ValidateParameterBinding(ValidationManager manager, Activity activity, bool isEvent, string operation, MethodInfo mInfo, WorkflowParameterBindingCollection parameterBindings, ValidationErrorCollection validationErrors)
{
Hashtable parameterCollection = new Hashtable();
ParameterInfo[] parameters = mInfo.GetParameters();
bool canBeIntercepted = false;
foreach (ParameterInfo parameter in parameters)
{
if (TypeProvider.IsAssignable(typeof(ExternalDataEventArgs), parameter.ParameterType))
{
if (parameter.Position == 1)
canBeIntercepted = true;
ValidateParameterSerializabiltiy(validationErrors, parameter.ParameterType);
}
parameterCollection.Add(parameter.Name, parameter);
}
if (isEvent && (!canBeIntercepted || parameters.Length != 2))
validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_InvalidEventArgsSignature, operation)), ErrorNumbers.Error_FieldNotExists, false, "EventName"));
if (mInfo.ReturnType != typeof(void))
parameterCollection.Add("(ReturnValue)", mInfo.ReturnParameter);
foreach (WorkflowParameterBinding parameterBinding in parameterBindings)
{
string paramName = parameterBinding.ParameterName;
if (!parameterCollection.ContainsKey(paramName))
{
if (isEvent)
validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_InvalidEventPropertyName, paramName)), ErrorNumbers.Error_FieldNotExists, false, "ParameterBindings"));
else
validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_InvalidMethodPropertyName, paramName)), ErrorNumbers.Error_FieldNotExists, false, "ParameterBindings"));
continue;
}
object paramValue = null;
if (parameterBinding.IsBindingSet(WorkflowParameterBinding.ValueProperty))
paramValue = parameterBinding.GetBinding(WorkflowParameterBinding.ValueProperty);
else
paramValue = parameterBinding.GetValue(WorkflowParameterBinding.ValueProperty);
if (paramValue == null)
continue;
ParameterInfo paramInfo = parameterCollection[paramName] as ParameterInfo;
if (paramInfo != null)
{
AccessTypes access = AccessTypes.Read;
if (paramInfo.IsOut || paramInfo.IsRetval)
access = AccessTypes.Write;
else if (paramInfo.ParameterType.IsByRef)
access |= AccessTypes.Write;
ValidationErrorCollection variableErrors = ValidationHelpers.ValidateProperty(manager, activity, paramValue,
new PropertyValidationContext(parameterBinding, null, paramName),
new BindValidationContext(paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType, access));
validationErrors.AddRange(variableErrors);
}
}
}
示例13: Validate
internal static ValidationErrorCollection Validate(ValidationManager manager, Object obj)
{
ValidationErrorCollection validationErrors = new ValidationErrorCollection();
Activity activity = obj as Activity;
if (!(activity is CallExternalMethodActivity) && !(activity is HandleExternalEventActivity))
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(Activity).FullName), "obj");
Type interfaceType = (activity is CallExternalMethodActivity) ? ((CallExternalMethodActivity)activity).InterfaceType : ((HandleExternalEventActivity)activity).InterfaceType;
if (interfaceType == null)
return validationErrors;
if (interfaceType.ContainsGenericParameters)
{
ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_GenericMethodsNotSupported), interfaceType.FullName), ErrorNumbers.Error_GenericMethodsNotSupported);
error.PropertyName = "InterfaceType";
validationErrors.Add(error);
return validationErrors;
}
object[] attributes = interfaceType.GetCustomAttributes(typeof(ExternalDataExchangeAttribute), false);
if (attributes.Length == 0)
{
ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_ExternalDataExchangeException), interfaceType.FullName), ErrorNumbers.Error_TypeNotExist);
error.PropertyName = "InterfaceType";
validationErrors.Add(error);
return validationErrors;
}
if (activity.Site == null)
{
ValidationErrorCollection interfaceErrors = ValidateHostInterface(manager, interfaceType, activity);
if (interfaceErrors.Count != 0)
{
validationErrors.AddRange(interfaceErrors);
return validationErrors;
}
}
MemberInfo targetMember = null;
if (activity is CallExternalMethodActivity)
{
if (((CallExternalMethodActivity)activity).MethodName == null || ((CallExternalMethodActivity)activity).MethodName.Length == 0)
return validationErrors;
MethodInfo methodInfo = interfaceType.GetMethod(((CallExternalMethodActivity)activity).MethodName, BindingFlags.Instance | BindingFlags.Public);
if (methodInfo == null || methodInfo.IsSpecialName)
{
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MissingMethodName, activity.Name, ((CallExternalMethodActivity)activity).MethodName), ErrorNumbers.Error_MissingMethodName));
return validationErrors;
}
if (methodInfo.ContainsGenericParameters)
{
ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_GenericMethodsNotSupported), methodInfo.Name), ErrorNumbers.Error_GenericMethodsNotSupported);
error.PropertyName = "MethodName";
validationErrors.Add(error);
return validationErrors;
}
targetMember = methodInfo;
}
else
{
if (((HandleExternalEventActivity)activity).EventName == null || ((HandleExternalEventActivity)activity).EventName.Length == 0)
return validationErrors;
EventInfo eventInfo = interfaceType.GetEvent(((HandleExternalEventActivity)activity).EventName, BindingFlags.Instance | BindingFlags.Public);
if (eventInfo == null)
{
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MissingEventName, activity.Name, ((HandleExternalEventActivity)activity).EventName), ErrorNumbers.Error_MissingMethodName));
return validationErrors;
}
targetMember = eventInfo;
}
attributes = interfaceType.GetCustomAttributes(typeof(CorrelationProviderAttribute), false);
if (attributes.Length != 0)
return validationErrors;
CorrelationToken correlator = activity.GetValue((activity is CallExternalMethodActivity) ? CallExternalMethodActivity.CorrelationTokenProperty : HandleExternalEventActivity.CorrelationTokenProperty) as CorrelationToken;
object[] correlationParameterAttributes = interfaceType.GetCustomAttributes(typeof(CorrelationParameterAttribute), false);
if (correlationParameterAttributes.Length == 0)
{
if (correlator != null)
validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_CorrelationTokenSpecifiedForUncorrelatedInterface), activity.QualifiedName, interfaceType), ErrorNumbers.Error_InvalidIdentifier, false, "CorrelationToken"));
return validationErrors;
}
// Someone derived from the activity and compiled, don't generate errors (P || C) validation.
if (activity.Parent == null)
return validationErrors;
if (correlator == null || String.IsNullOrEmpty(correlator.Name))
{
validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_MissingCorrelationTokenProperty), activity.QualifiedName), ErrorNumbers.Error_ParameterPropertyNotSet, false, "CorrelationToken"));
return validationErrors;
}
if (String.IsNullOrEmpty(correlator.OwnerActivityName))
//.........这里部分代码省略.........
示例14: ValidateProperty
protected internal ValidationErrorCollection ValidateProperty(PropertyInfo propertyInfo, object propertyOwner, object propertyValue, ValidationManager manager)
{
ValidationErrorCollection errors = new ValidationErrorCollection();
object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(ValidationOptionAttribute), true);
if (customAttributes.Length > 0)
{
ValidationOption validationOption = ((ValidationOptionAttribute) customAttributes[0]).ValidationOption;
}
PropertyValidationContext context = new PropertyValidationContext(propertyOwner, propertyInfo, propertyInfo.Name);
manager.Context.Push(context);
try
{
if (propertyValue == null)
{
return errors;
}
errors.AddRange(ValidationHelpers.ValidateObject(manager, propertyValue));
if (!(propertyValue is IList))
{
return errors;
}
PropertyValidationContext context2 = new PropertyValidationContext(propertyValue, null, "");
manager.Context.Push(context2);
try
{
foreach (object obj2 in (IList) propertyValue)
{
errors.AddRange(ValidationHelpers.ValidateObject(manager, obj2));
}
return errors;
}
finally
{
manager.Context.Pop();
}
}
finally
{
manager.Context.Pop();
}
return errors;
}
示例15: ValidateObject
internal static ValidationErrorCollection ValidateObject(ValidationManager manager, object obj)
{
ValidationErrorCollection errors = new ValidationErrorCollection();
if (obj != null)
{
Type type = obj.GetType();
if (type.IsPrimitive || !(type != typeof(string)))
{
return errors;
}
bool flag = false;
Dictionary<int, object> context = manager.Context[typeof(Dictionary<int, object>)] as Dictionary<int, object>;
if (context == null)
{
context = new Dictionary<int, object>();
manager.Context.Push(context);
flag = true;
}
try
{
if (context.ContainsKey(obj.GetHashCode()))
{
return errors;
}
context.Add(obj.GetHashCode(), obj);
try
{
foreach (Validator validator in manager.GetValidators(type))
{
errors.AddRange(validator.Validate(manager, obj));
}
}
finally
{
context.Remove(obj.GetHashCode());
}
}
finally
{
if (flag)
{
manager.Context.Pop();
}
}
}
return errors;
}