本文整理汇总了C#中System.Workflow.ComponentModel.Compiler.ValidationManager.GetValidators方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationManager.GetValidators方法的具体用法?C# ValidationManager.GetValidators怎么用?C# ValidationManager.GetValidators使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Workflow.ComponentModel.Compiler.ValidationManager
的用法示例。
在下文中一共展示了ValidationManager.GetValidators方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: ValidateDefinition
void ValidateDefinition()
{
ValidationErrorCollection errors = new ValidationErrorCollection();
Activity rootActivity = GetWorkflowDefinition();
ITypeProvider typeProvider = CreateTypeProvider(rootActivity);
ServiceContainer serviceContainer = new ServiceContainer();
serviceContainer.AddService(typeof(ITypeProvider), typeProvider);
ValidationManager validationManager = new ValidationManager(serviceContainer);
foreach (Validator validator in validationManager.GetValidators(rootActivity.GetType()))
{
foreach (ValidationError error in validator.Validate(validationManager, rootActivity))
{
if (!error.UserData.Contains(typeof(Activity)))
{
error.UserData[typeof(Activity)] = rootActivity;
}
errors.Add(error);
}
}
OnValidate(errors);
if (errors.HasErrors)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WorkflowValidationFailedException(SR2.WorkflowValidationFailed, errors));
}
}
示例3: 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;
}
示例4: ValidateActivity
internal static void ValidateActivity(Activity activity, WorkflowCompilerParameters parameters, WorkflowCompilerResults results)
{
ValidationManager manager = new ValidationManager(WorkflowCompilationContext.Current.ServiceProvider);
foreach (Validator validator in manager.GetValidators(activity.GetType()))
{
try
{
foreach (ValidationError error in validator.Validate(manager, activity))
{
if (!error.UserData.Contains(typeof(Activity)))
{
error.UserData[typeof(Activity)] = activity;
}
results.Errors.Add(CreateXomlCompilerError(error, parameters));
}
}
catch (TargetInvocationException exception)
{
Exception exception2 = exception.InnerException ?? exception;
ValidationError error2 = new ValidationError(SR.GetString("Error_ValidatorThrewException", new object[] { exception2.GetType().FullName, validator.GetType().FullName, activity.Name, exception2.ToString() }), 0x627);
results.Errors.Add(CreateXomlCompilerError(error2, parameters));
}
catch (Exception exception3)
{
ValidationError error3 = new ValidationError(SR.GetString("Error_ValidatorThrewException", new object[] { exception3.GetType().FullName, validator.GetType().FullName, activity.Name, exception3.ToString() }), 0x627);
results.Errors.Add(CreateXomlCompilerError(error3, parameters));
}
}
}
示例5: ValidateActivity
internal static void ValidateActivity(Activity activity, WorkflowCompilerParameters parameters, WorkflowCompilerResults results)
{
ValidationErrorCollection errors = null;
ValidationManager validationManager = new ValidationManager(WorkflowCompilationContext.Current.ServiceProvider);
foreach (Validator validator in validationManager.GetValidators(activity.GetType()))
{
// Validate recursively.
try
{
errors = validator.Validate(validationManager, activity);
foreach (ValidationError error in errors)
{
if (!error.UserData.Contains(typeof(Activity)))
error.UserData[typeof(Activity)] = activity;
results.Errors.Add(CreateXomlCompilerError(error, parameters));
}
}
catch (TargetInvocationException tie)
{
Exception e = tie.InnerException ?? tie;
ValidationError error = new ValidationError(SR.GetString(SR.Error_ValidatorThrewException, e.GetType().FullName, validator.GetType().FullName, activity.Name, e.ToString()), ErrorNumbers.Error_ValidatorThrewException);
results.Errors.Add(CreateXomlCompilerError(error, parameters));
}
catch (Exception e)
{
ValidationError error = new ValidationError(SR.GetString(SR.Error_ValidatorThrewException, e.GetType().FullName, validator.GetType().FullName, activity.Name, e.ToString()), ErrorNumbers.Error_ValidatorThrewException);
results.Errors.Add(CreateXomlCompilerError(error, parameters));
}
}
}