public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); PropertyBind bind = obj as PropertyBind; if (bind == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(PropertyBind).FullName }), "obj"); } PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext; if (validationContext == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name })); } Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name })); } ValidationError item = null; if (string.IsNullOrEmpty(bind.Name)) { item = new ValidationError(SR.GetString("Error_PropertyNotSet", new object[] { "Name" }), 0x116) { PropertyName = base.GetFullPropertyName(manager) + ".Name" }; } else { BindValidationContext context2 = manager.Context[typeof(BindValidationContext)] as BindValidationContext; if (context2 == null) { Type baseType = BindHelpers.GetBaseType(manager, validationContext); if (baseType != null) { AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext); context2 = new BindValidationContext(baseType, accessType); } } if (context2 != null) { Type targetType = context2.TargetType; if (item == null) { errors.AddRange(this.ValidateBindProperty(manager, activity, bind, new BindValidationContext(targetType, context2.Access))); } } } if (item != null) { errors.Add(item); } return(errors); }
private ValidationErrorCollection ValidateActivityBind(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); ActivityBind bind = obj as ActivityBind; PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext; if (validationContext == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name })); } if (!(manager.Context[typeof(Activity)] is Activity)) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name })); } ValidationError item = null; BindValidationContext context2 = manager.Context[typeof(BindValidationContext)] as BindValidationContext; if (context2 == null) { Type baseType = BindHelpers.GetBaseType(manager, validationContext); if (baseType != null) { AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext); context2 = new BindValidationContext(baseType, accessType); } } if (context2 != null) { Type targetType = context2.TargetType; if (item == null) { errors.AddRange(this.ValidateActivity(manager, bind, new BindValidationContext(targetType, context2.Access))); } } if (item != null) { errors.Add(item); } return(errors); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); ActivityBind bind = obj as ActivityBind; if (bind == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityBind).FullName }), "obj"); } Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name })); } PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext; if (validationContext == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name })); } ValidationError item = null; if (string.IsNullOrEmpty(bind.Name)) { item = new ValidationError(SR.GetString("Error_IDNotSetForActivitySource"), 0x613) { PropertyName = base.GetFullPropertyName(manager) + ".Name" }; errors.Add(item); return(errors); } Activity refActivity = Helpers.ParseActivityForBind(activity, bind.Name); if (refActivity == null) { if (bind.Name.StartsWith("/")) { item = new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128); } else { item = new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129); } item.PropertyName = base.GetFullPropertyName(manager) + ".Name"; errors.Add(item); } if (string.IsNullOrEmpty(bind.Path)) { item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; errors.Add(item); } if ((refActivity != null) && (errors.Count == 0)) { string path = bind.Path; string str2 = string.Empty; int startIndex = path.IndexOfAny(new char[] { '.', '/', '[' }); if (startIndex != -1) { str2 = path.Substring(startIndex); str2 = str2.StartsWith(".") ? str2.Substring(1) : str2; path = path.Substring(0, startIndex); } Type baseType = BindHelpers.GetBaseType(manager, validationContext); MemberInfo memberInfo = null; Type srcType = null; if (!string.IsNullOrEmpty(path)) { srcType = BindValidatorHelper.GetActivityType(manager, refActivity); if (srcType != null) { memberInfo = MemberBind.GetMemberInfo(srcType, path); if ((memberInfo == null) && str2.StartsWith("[", StringComparison.Ordinal)) { string str3 = bind.Path.Substring(startIndex); int index = str3.IndexOf(']'); if (index != -1) { string str4 = str3.Substring(0, index + 1); str2 = ((index + 1) < str3.Length) ? str3.Substring(index + 1) : string.Empty; str2 = str2.StartsWith(".") ? str2.Substring(1) : str2; str3 = str4; } path = path + str3; memberInfo = MemberBind.GetMemberInfo(srcType, path); } } } Validator validator = null; object obj2 = null; if (memberInfo != null) { string str5 = !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : bind.Name; if (memberInfo is FieldInfo) { obj2 = new FieldBind(str5 + "." + path, str2); validator = new FieldBindValidator(); } else if (memberInfo is MethodInfo) { if (typeof(Delegate).IsAssignableFrom(baseType)) { obj2 = new MethodBind(str5 + "." + path); validator = new MethodBindValidator(); } else { item = new ValidationError(SR.GetString("Error_InvalidMemberType", new object[] { path, base.GetFullPropertyName(manager) }), 0x629) { PropertyName = base.GetFullPropertyName(manager) }; errors.Add(item); } } else if (memberInfo is PropertyInfo) { if (refActivity == activity) { obj2 = new PropertyBind(str5 + "." + path, str2); validator = new PropertyBindValidator(); } else { obj2 = bind; validator = this; } } else if (memberInfo is EventInfo) { obj2 = bind; validator = this; } } else if (((memberInfo == null) && (baseType != null)) && typeof(Delegate).IsAssignableFrom(baseType)) { obj2 = bind; validator = this; } if ((validator != null) && (obj2 != null)) { if ((validator == this) && (obj2 is ActivityBind)) { errors.AddRange(this.ValidateActivityBind(manager, obj2)); return(errors); } errors.AddRange(validator.Validate(manager, obj2)); return(errors); } if (item == null) { item = new ValidationError(SR.GetString("Error_PathCouldNotBeResolvedToMember", new object[] { bind.Path, !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : refActivity.GetType().Name }), 0x60d) { PropertyName = base.GetFullPropertyName(manager) }; errors.Add(item); } } return(errors); }