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);
        }
 public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
 {
     ValidationErrorCollection errors = base.Validate(manager, obj);
     MethodBind bind = obj as MethodBind;
     if (bind == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(MethodBind).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.ValidateMethod(manager, activity, bind, new BindValidationContext(targetType, context2.Access)));
             }
         }
     }
     if (item != null)
     {
         errors.Add(item);
     }
     return errors;
 }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

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

            PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;
            if (validationContext == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(BindValidationContext).Name));

            Activity activity = manager.Context[typeof(Activity)] as Activity;
            if (activity == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(Activity).Name));

            ValidationError error = null;
            if (string.IsNullOrEmpty(bind.Name))
            {
                error = new ValidationError(SR.GetString(SR.Error_PropertyNotSet, "Name"), ErrorNumbers.Error_PropertyNotSet);
                error.PropertyName = GetFullPropertyName(manager) + ".Name";
            }
            else
            {
                BindValidationContext validationBindContext = manager.Context[typeof(BindValidationContext)] as BindValidationContext;
                if (validationBindContext == null)
                {
                    Type baseType = BindHelpers.GetBaseType(manager, validationContext);
                    if (baseType != null)
                    {
                        AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext);
                        validationBindContext = new BindValidationContext(baseType, accessType);
                    }
                    //else
                    //{
                    //    error = new ValidationError(SR.GetString(SR.Error_BindBaseTypeNotSpecified, validationContext.PropertyName), ErrorNumbers.Error_BindBaseTypeNotSpecified);
                    //    error.PropertyName = GetFullPropertyName(manager) + ".Name";
                    //}
                }
                if (validationBindContext != null)
                {
                    Type targetType = validationBindContext.TargetType;
                    if (error == null)
                        validationErrors.AddRange(this.ValidateField(manager, activity, bind, new BindValidationContext(targetType, validationBindContext.Access)));
                }
            }
            if (error != null)
                validationErrors.Add(error);

            return validationErrors;
        }
Example #4
0
        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);
        }
        private ValidationErrorCollection ValidateBindProperty(ValidationManager manager, Activity activity, PropertyBind bind, BindValidationContext validationContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
            Activity refActivity       = enclosingActivity;

            if ((name.IndexOf('.') != -1) && (refActivity != null))
            {
                refActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (refActivity == null)
            {
                ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error);
                return(errors);
            }
            ValidationError item         = null;
            PropertyInfo    property     = null;
            Type            activityType = null;

            if (property == null)
            {
                activityType = BindValidatorHelper.GetActivityType(manager, refActivity);
                if (activityType != null)
                {
                    property = activityType.GetProperty(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                }
            }
            if (activityType == null)
            {
                item = new ValidationError(SR.GetString("Error_TypeNotResolvedInPropertyName", new object[] { "Name" }), 0x163)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x164)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (!property.CanRead)
            {
                item = new ValidationError(SR.GetString("Error_PropertyReferenceNoGetter", new object[] { base.GetFullPropertyName(manager), name }), 360)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property.GetGetMethod() == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyReferenceGetterNoAccess", new object[] { base.GetFullPropertyName(manager), name }), 0x60a)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (((refActivity != enclosingActivity) && !property.GetGetMethod().IsAssembly) && !property.GetGetMethod().IsPublic)
            {
                item = new ValidationError(SR.GetString("Error_PropertyNotAccessible", new object[] { base.GetFullPropertyName(manager), name }), 0x165)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property.PropertyType == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 0x166)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else
            {
                MemberInfo memberInfo = property;
                if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, property.PropertyType, validationContext.Access)))
                {
                    item = new ValidationError(SR.GetString("Error_PropertyTypeMismatch", new object[] { base.GetFullPropertyName(manager), property.PropertyType.FullName, validationContext.TargetType.FullName }), 0x167)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else if (!string.IsNullOrEmpty(bind.Path))
                {
                    memberInfo = MemberBind.GetMemberInfo(property.PropertyType, bind.Path);
                    if (memberInfo == null)
                    {
                        item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300)
                        {
                            PropertyName = base.GetFullPropertyName(manager) + ".Path"
                        };
                    }
                    else
                    {
                        using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                        {
                            if (WorkflowCompilationContext.Current.CheckTypes)
                            {
                                item = MemberBind.ValidateTypesInPath(property.PropertyType, bind.Path);
                                if (item != null)
                                {
                                    item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                                }
                            }
                        }
                        if (item == null)
                        {
                            Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                            if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                    }
                }
                if (item == null)
                {
                    if (memberInfo is PropertyInfo)
                    {
                        PropertyInfo info3 = memberInfo as PropertyInfo;
                        if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                    else if (memberInfo is FieldInfo)
                    {
                        FieldInfo info4 = memberInfo as FieldInfo;
                        if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
        private ValidationErrorCollection ValidateField(ValidationManager manager, Activity activity, FieldBind bind, BindValidationContext validationContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);

            if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
            {
                enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (enclosingActivity == null)
            {
                ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error);
                return(errors);
            }
            ValidationError item            = null;
            Type            dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);

            if (dataSourceClass == null)
            {
                item = new ValidationError(SR.GetString("Error_TypeNotResolvedInFieldName", new object[] { "Name" }), 0x11f)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else
            {
                FieldInfo field = dataSourceClass.GetField(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (field == null)
                {
                    item = new ValidationError(SR.GetString("Error_FieldNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x120)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else if (field.FieldType == null)
                {
                    item = new ValidationError(SR.GetString("Error_FieldTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 290)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else
                {
                    MemberInfo memberInfo = field;
                    if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, field.FieldType, validationContext.Access)))
                    {
                        item = new ValidationError(SR.GetString("Error_FieldTypeMismatch", new object[] { base.GetFullPropertyName(manager), field.FieldType.FullName, validationContext.TargetType.FullName }), 0x13f)
                        {
                            PropertyName = base.GetFullPropertyName(manager)
                        };
                    }
                    else if (!string.IsNullOrEmpty(bind.Path))
                    {
                        memberInfo = MemberBind.GetMemberInfo(field.FieldType, bind.Path);
                        if (memberInfo == null)
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else
                        {
                            using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                            {
                                if (WorkflowCompilationContext.Current.CheckTypes)
                                {
                                    item = MemberBind.ValidateTypesInPath(field.FieldType, bind.Path);
                                    if (item != null)
                                    {
                                        item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                                    }
                                }
                            }
                            if (item == null)
                            {
                                Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                                if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                    }
                    if (item == null)
                    {
                        if (memberInfo is PropertyInfo)
                        {
                            PropertyInfo info3 = memberInfo as PropertyInfo;
                            if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                            else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                        else if (memberInfo is FieldInfo)
                        {
                            FieldInfo info4 = memberInfo as FieldInfo;
                            if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
 private ValidationErrorCollection ValidateMethod(ValidationManager manager, Activity activity, MethodBind bind, BindValidationContext validationBindContext)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection();
     if ((validationBindContext.Access & AccessTypes.Write) != 0)
     {
         ValidationError item = new ValidationError(SR.GetString("Error_HandlerReadOnly"), 0x133) {
             PropertyName = base.GetFullPropertyName(manager)
         };
         errors.Add(item);
         return errors;
     }
     if (!TypeProvider.IsAssignable(typeof(Delegate), validationBindContext.TargetType))
     {
         ValidationError error2 = new ValidationError(SR.GetString("Error_TypeNotDelegate", new object[] { validationBindContext.TargetType.FullName }), 0x134) {
             PropertyName = base.GetFullPropertyName(manager)
         };
         errors.Add(error2);
         return errors;
     }
     string name = bind.Name;
     Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
     if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
     {
         enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
     }
     if (enclosingActivity == null)
     {
         ValidationError error3 = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130) {
             PropertyName = base.GetFullPropertyName(manager) + ".Name"
         };
         errors.Add(error3);
         return errors;
     }
     string errorText = string.Empty;
     int errorNumber = -1;
     Type dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);
     if (dataSourceClass == null)
     {
         errorText = SR.GetString("Error_TypeNotResolvedInMethodName", new object[] { base.GetFullPropertyName(manager) + ".Name" });
         errorNumber = 0x135;
     }
     else
     {
         try
         {
             ValidationHelpers.ValidateIdentifier(manager, name);
         }
         catch (Exception exception)
         {
             errors.Add(new ValidationError(exception.Message, 0x119));
         }
         MethodInfo method = validationBindContext.TargetType.GetMethod("Invoke");
         if (method == null)
         {
             throw new Exception(SR.GetString("Error_DelegateNoInvoke", new object[] { validationBindContext.TargetType.FullName }));
         }
         List<Type> list = new List<Type>();
         foreach (ParameterInfo info2 in method.GetParameters())
         {
             list.Add(info2.ParameterType);
         }
         MethodInfo info3 = Helpers.GetMethodExactMatch(dataSourceClass, name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, list.ToArray(), null);
         if (info3 == null)
         {
             if (dataSourceClass.GetMethod(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance) != null)
             {
                 errorText = SR.GetString("Error_MethodSignatureMismatch", new object[] { base.GetFullPropertyName(manager) + ".Name" });
                 errorNumber = 310;
             }
             else
             {
                 errorText = SR.GetString("Error_MethodNotExists", new object[] { base.GetFullPropertyName(manager) + ".Name", bind.Name });
                 errorNumber = 0x137;
             }
         }
         else if (!method.ReturnType.Equals(info3.ReturnType))
         {
             errorText = SR.GetString("Error_MethodReturnTypeMismatch", new object[] { base.GetFullPropertyName(manager), method.ReturnType.FullName });
             errorNumber = 0x139;
         }
     }
     if (errorText.Length > 0)
     {
         ValidationError error4 = new ValidationError(errorText, errorNumber) {
             PropertyName = base.GetFullPropertyName(manager) + ".Path"
         };
         errors.Add(error4);
     }
     return errors;
 }
Example #8
0
        private ValidationErrorCollection ValidateMethod(ValidationManager manager, Activity activity, MethodBind bind, BindValidationContext validationBindContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            if ((validationBindContext.Access & AccessTypes.Write) != 0)
            {
                ValidationError item = new ValidationError(SR.GetString("Error_HandlerReadOnly"), 0x133)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
                errors.Add(item);
                return(errors);
            }
            if (!TypeProvider.IsAssignable(typeof(Delegate), validationBindContext.TargetType))
            {
                ValidationError error2 = new ValidationError(SR.GetString("Error_TypeNotDelegate", new object[] { validationBindContext.TargetType.FullName }), 0x134)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
                errors.Add(error2);
                return(errors);
            }
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);

            if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
            {
                enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (enclosingActivity == null)
            {
                ValidationError error3 = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error3);
                return(errors);
            }
            string errorText       = string.Empty;
            int    errorNumber     = -1;
            Type   dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);

            if (dataSourceClass == null)
            {
                errorText   = SR.GetString("Error_TypeNotResolvedInMethodName", new object[] { base.GetFullPropertyName(manager) + ".Name" });
                errorNumber = 0x135;
            }
            else
            {
                try
                {
                    ValidationHelpers.ValidateIdentifier(manager, name);
                }
                catch (Exception exception)
                {
                    errors.Add(new ValidationError(exception.Message, 0x119));
                }
                MethodInfo method = validationBindContext.TargetType.GetMethod("Invoke");
                if (method == null)
                {
                    throw new Exception(SR.GetString("Error_DelegateNoInvoke", new object[] { validationBindContext.TargetType.FullName }));
                }
                List <Type> list = new List <Type>();
                foreach (ParameterInfo info2 in method.GetParameters())
                {
                    list.Add(info2.ParameterType);
                }
                MethodInfo info3 = Helpers.GetMethodExactMatch(dataSourceClass, name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, list.ToArray(), null);
                if (info3 == null)
                {
                    if (dataSourceClass.GetMethod(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance) != null)
                    {
                        errorText   = SR.GetString("Error_MethodSignatureMismatch", new object[] { base.GetFullPropertyName(manager) + ".Name" });
                        errorNumber = 310;
                    }
                    else
                    {
                        errorText   = SR.GetString("Error_MethodNotExists", new object[] { base.GetFullPropertyName(manager) + ".Name", bind.Name });
                        errorNumber = 0x137;
                    }
                }
                else if (!method.ReturnType.Equals(info3.ReturnType))
                {
                    errorText   = SR.GetString("Error_MethodReturnTypeMismatch", new object[] { base.GetFullPropertyName(manager), method.ReturnType.FullName });
                    errorNumber = 0x139;
                }
            }
            if (errorText.Length > 0)
            {
                ValidationError error4 = new ValidationError(errorText, errorNumber)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
                errors.Add(error4);
            }
            return(errors);
        }
        private ValidationErrorCollection ValidateField(ValidationManager manager, Activity activity, FieldBind bind, BindValidationContext validationContext)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();

            string dsName = bind.Name;
            Activity activityContext = Helpers.GetEnclosingActivity(activity);
            Activity dataSourceActivity = activityContext;
            if (dsName.IndexOf('.') != -1 && dataSourceActivity != null)
                dataSourceActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out dsName);

            if (dataSourceActivity == null)
            {
                ValidationError error = new ValidationError(SR.GetString(SR.Error_NoEnclosingContext, activity.Name), ErrorNumbers.Error_NoEnclosingContext);
                error.PropertyName = GetFullPropertyName(manager) + ".Name";
                validationErrors.Add(error);
            }
            else
            {
                ValidationError error = null;
                // 
                System.Type resolvedType = Helpers.GetDataSourceClass(dataSourceActivity, manager);
                if (resolvedType == null)
                {
                    error = new ValidationError(SR.GetString(SR.Error_TypeNotResolvedInFieldName, "Name"), ErrorNumbers.Error_TypeNotResolvedInFieldName);
                    error.PropertyName = GetFullPropertyName(manager);
                }
                else
                {
                    FieldInfo fieldInfo = resolvedType.GetField(dsName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                    if (fieldInfo == null)
                    {
                        error = new ValidationError(SR.GetString(SR.Error_FieldNotExists, GetFullPropertyName(manager), dsName), ErrorNumbers.Error_FieldNotExists);
                        error.PropertyName = GetFullPropertyName(manager);
                    }
                    //else if (dataSourceActivity != activityContext && !fieldInfo.IsAssembly && !fieldInfo.IsPublic)
                    //{
                    //    error = new ValidationError(SR.GetString(SR.Error_FieldNotAccessible, GetFullPropertyName(manager), dsName), ErrorNumbers.Error_FieldNotAccessible);
                    //    error.PropertyName = GetFullPropertyName(manager);
                    //}
                    else if (fieldInfo.FieldType == null)
                    {
                        error = new ValidationError(SR.GetString(SR.Error_FieldTypeNotResolved, GetFullPropertyName(manager), dsName), ErrorNumbers.Error_FieldTypeNotResolved);
                        error.PropertyName = GetFullPropertyName(manager);
                    }
                    else
                    {
                        MemberInfo memberInfo = fieldInfo;
                        if ((bind.Path == null || bind.Path.Length == 0) && (validationContext.TargetType != null && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, fieldInfo.FieldType, validationContext.Access)))
                        {
                            error = new ValidationError(SR.GetString(SR.Error_FieldTypeMismatch, GetFullPropertyName(manager), fieldInfo.FieldType.FullName, validationContext.TargetType.FullName), ErrorNumbers.Error_FieldTypeMismatch);
                            error.PropertyName = GetFullPropertyName(manager);
                        }
                        else if (!string.IsNullOrEmpty(bind.Path))
                        {
                            memberInfo = MemberBind.GetMemberInfo(fieldInfo.FieldType, bind.Path);
                            if (memberInfo == null)
                            {
                                error = new ValidationError(SR.GetString(SR.Error_InvalidMemberPath, dsName, bind.Path), ErrorNumbers.Error_InvalidMemberPath);
                                error.PropertyName = GetFullPropertyName(manager) + ".Path";
                            }
                            else
                            {
                                IDisposable localContextScope = (WorkflowCompilationContext.Current == null ? WorkflowCompilationContext.CreateScope(manager) : null);
                                try
                                {
                                    if (WorkflowCompilationContext.Current.CheckTypes)
                                    {
                                        error = MemberBind.ValidateTypesInPath(fieldInfo.FieldType, bind.Path);
                                        if (error != null)
                                            error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                    }
                                }
                                finally
                                {
                                    if (localContextScope != null)
                                    {
                                        localContextScope.Dispose();
                                    }
                                }

                                if (error == null)
                                {
                                    Type memberType = (memberInfo is FieldInfo ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType);
                                    if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                                    {
                                        error = new ValidationError(SR.GetString(SR.Error_TargetTypeDataSourcePathMismatch, validationContext.TargetType.FullName), ErrorNumbers.Error_TargetTypeDataSourcePathMismatch);
                                        error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                    }
                                }
                            }
                        }
                        if (error == null)
                        {
                            if (memberInfo is PropertyInfo)
                            {
                                PropertyInfo pathPropertyInfo = memberInfo as PropertyInfo;
                                if (!pathPropertyInfo.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                                {
                                    error = new ValidationError(SR.GetString(SR.Error_PropertyNoGetter, pathPropertyInfo.Name, bind.Path), ErrorNumbers.Error_PropertyNoGetter);
                                    error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                }
                                else if (!pathPropertyInfo.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                                {
                                    error = new ValidationError(SR.GetString(SR.Error_PropertyNoSetter, pathPropertyInfo.Name, bind.Path), ErrorNumbers.Error_PropertyNoSetter);
                                    error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                }
                            }
                            else if (memberInfo is FieldInfo)
                            {
                                FieldInfo pathFieldInfo = memberInfo as FieldInfo;
                                if (((pathFieldInfo.Attributes & (FieldAttributes.InitOnly | FieldAttributes.Literal)) != 0) &&
                                    ((validationContext.Access & AccessTypes.Write) != 0))
                                {
                                    error = new ValidationError(SR.GetString(SR.Error_ReadOnlyField, pathFieldInfo.Name), ErrorNumbers.Error_ReadOnlyField);
                                    error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                }
                            }
                        }
                    }
                }
                if (error != null)
                    validationErrors.Add(error);
            }
            return validationErrors;
        }
        private ValidationErrorCollection ValidateActivity(ValidationManager manager, ActivityBind bind, BindValidationContext validationContext)
        {
            ValidationError error = null;
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();

            Activity activity = manager.Context[typeof(Activity)] as Activity;
            if (activity == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(Activity).Name));

            Activity refActivity = Helpers.ParseActivityForBind(activity, bind.Name);
            if (refActivity == null)
            {
                error = (bind.Name.StartsWith("/", StringComparison.Ordinal)) ? new ValidationError(SR.GetString(SR.Error_CannotResolveRelativeActivity, bind.Name), ErrorNumbers.Error_CannotResolveRelativeActivity) : new ValidationError(SR.GetString(SR.Error_CannotResolveActivity, bind.Name), ErrorNumbers.Error_CannotResolveActivity);
                error.PropertyName = GetFullPropertyName(manager) + ".Name";
            }
            else if (bind.Path == null || bind.Path.Length == 0)
            {
                error = new ValidationError(SR.GetString(SR.Error_PathNotSetForActivitySource), ErrorNumbers.Error_PathNotSetForActivitySource);
                error.PropertyName = GetFullPropertyName(manager) + ".Path";
            }
            else
            {
                // 

                if (!bind.Name.StartsWith("/", StringComparison.Ordinal) && !ValidationHelpers.IsActivitySourceInOrder(refActivity, activity))
                {
                    error = new ValidationError(SR.GetString(SR.Error_BindActivityReference, refActivity.QualifiedName, activity.QualifiedName), ErrorNumbers.Error_BindActivityReference, true);
                    error.PropertyName = GetFullPropertyName(manager) + ".Name";
                }

                IDesignerHost designerHost = manager.GetService(typeof(IDesignerHost)) as IDesignerHost;
                WorkflowDesignerLoader loader = manager.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                if (designerHost != null && loader != null)
                {
                    Type refActivityType = null;
                    if (designerHost.RootComponent == refActivity)
                    {
                        ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                        if (typeProvider == null)
                            throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));

                        refActivityType = typeProvider.GetType(designerHost.RootComponentClassName);
                    }
                    else
                    {
                        refActivity.GetType();
                    }

                    if (refActivityType != null)
                    {
                        MemberInfo memberInfo = MemberBind.GetMemberInfo(refActivityType, bind.Path);
                        if (memberInfo == null || (memberInfo is PropertyInfo && !(memberInfo as PropertyInfo).CanRead))
                        {
                            error = new ValidationError(SR.GetString(SR.Error_InvalidMemberPath, refActivity.QualifiedName, bind.Path), ErrorNumbers.Error_InvalidMemberPath);
                            error.PropertyName = GetFullPropertyName(manager) + ".Path";
                        }
                        else
                        {
                            Type memberType = null;
                            if (memberInfo is FieldInfo)
                                memberType = ((FieldInfo)(memberInfo)).FieldType;
                            else if (memberInfo is PropertyInfo)
                                memberType = ((PropertyInfo)(memberInfo)).PropertyType;
                            else if (memberInfo is EventInfo)
                                memberType = ((EventInfo)(memberInfo)).EventHandlerType;

                            if (!DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType))
                                {
                                    error = new ValidationError(SR.GetString(SR.Warning_ParameterBinding, bind.Path, refActivity.QualifiedName, validationContext.TargetType.FullName), ErrorNumbers.Warning_ParameterBinding, true);
                                    error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                }
                                else
                                {
                                    error = new ValidationError(SR.GetString(SR.Error_TargetTypeMismatch, memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName), ErrorNumbers.Error_TargetTypeMismatch);
                                    error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                }
                            }
                        }
                    }
                }
                else
                {
                    MemberInfo memberInfo = MemberBind.GetMemberInfo(refActivity.GetType(), bind.Path);
                    if (memberInfo == null || (memberInfo is PropertyInfo && !(memberInfo as PropertyInfo).CanRead))
                    {
                        error = new ValidationError(SR.GetString(SR.Error_InvalidMemberPath, refActivity.QualifiedName, bind.Path), ErrorNumbers.Error_InvalidMemberPath);
                        error.PropertyName = GetFullPropertyName(manager) + ".Path";
                    }
                    else
                    {
                        DependencyProperty dependencyProperty = DependencyProperty.FromName(memberInfo.Name, memberInfo.DeclaringType);
                        object value = BindHelpers.ResolveActivityPath(refActivity, bind.Path);
                        if (value == null)
                        {
                            Type memberType = null;
                            if (memberInfo is FieldInfo)
                                memberType = ((FieldInfo)(memberInfo)).FieldType;
                            else if (memberInfo is PropertyInfo)
                                memberType = ((PropertyInfo)(memberInfo)).PropertyType;
                            else if (memberInfo is EventInfo)
                                memberType = ((EventInfo)(memberInfo)).EventHandlerType;

                            if (!TypeProvider.IsAssignable(typeof(ActivityBind), memberType) && !DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType))
                                {
                                    error = new ValidationError(SR.GetString(SR.Warning_ParameterBinding, bind.Path, refActivity.QualifiedName, validationContext.TargetType.FullName), ErrorNumbers.Warning_ParameterBinding, true);
                                    error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                }
                                else
                                {
                                    error = new ValidationError(SR.GetString(SR.Error_TargetTypeMismatch, memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName), ErrorNumbers.Error_TargetTypeMismatch);
                                    error.PropertyName = GetFullPropertyName(manager) + ".Path";
                                }
                            }
                        }
                        // If this is the top level activity, we should not valid that the bind can be resolved because
                        // the value of bind can be set when this activity is used in another activity.
                        else if (value is ActivityBind && refActivity.Parent != null)
                        {
                            ActivityBind referencedBind = value as ActivityBind;
                            bool bindRecursionContextAdded = false;

                            // Check for recursion
                            BindRecursionContext recursionContext = manager.Context[typeof(BindRecursionContext)] as BindRecursionContext;
                            if (recursionContext == null)
                            {
                                recursionContext = new BindRecursionContext();
                                manager.Context.Push(recursionContext);
                                bindRecursionContextAdded = true;
                            }
                            if (recursionContext.Contains(activity, bind))
                            {
                                error = new ValidationError(SR.GetString(SR.Bind_ActivityDataSourceRecursionDetected), ErrorNumbers.Bind_ActivityDataSourceRecursionDetected);
                                error.PropertyName = GetFullPropertyName(manager) + ".Path";
                            }
                            else
                            {
                                recursionContext.Add(activity, bind);

                                PropertyValidationContext propertyValidationContext = null;
                                if (dependencyProperty != null)
                                    propertyValidationContext = new PropertyValidationContext(refActivity, dependencyProperty);
                                else
                                    propertyValidationContext = new PropertyValidationContext(refActivity, memberInfo as PropertyInfo, memberInfo.Name);

                                validationErrors.AddRange(ValidationHelpers.ValidateProperty(manager, refActivity, referencedBind, propertyValidationContext, validationContext));
                            }

                            if (bindRecursionContextAdded)
                                manager.Context.Pop();
                        }
                        else if (validationContext.TargetType != null && !DoesTargetTypeMatch(validationContext.TargetType, value.GetType(), validationContext.Access))
                        {
                            error = new ValidationError(SR.GetString(SR.Error_TargetTypeMismatch, memberInfo.Name, value.GetType().FullName, validationContext.TargetType.FullName), ErrorNumbers.Error_TargetTypeMismatch);
                            error.PropertyName = GetFullPropertyName(manager) + ".Path";
                        }
                    }
                }
            }

            if (error != null)
                validationErrors.Add(error);

            return validationErrors;
        }
        private ValidationErrorCollection ValidateActivityBind(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = 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(SR.Error_ContextStackItemMissing, typeof(BindValidationContext).Name));

            Activity activity = manager.Context[typeof(Activity)] as Activity;
            if (activity == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(Activity).Name));

            ValidationError error = null;

            //Redirect from here to FieldBind/MethodBind by creating their instances
            BindValidationContext validationBindContext = manager.Context[typeof(BindValidationContext)] as BindValidationContext;
            if (validationBindContext == null)
            {
                Type baseType = BindHelpers.GetBaseType(manager, validationContext);
                if (baseType != null)
                {
                    AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext);
                    validationBindContext = new BindValidationContext(baseType, accessType);
                }
                //else
                //{
                //    error = new ValidationError(SR.GetString(SR.Error_BindBaseTypeNotSpecified, validationContext.PropertyName), ErrorNumbers.Error_BindBaseTypeNotSpecified);
                //    error.PropertyName = GetFullPropertyName(manager) + ".Name";
                //}
            }
            if (validationBindContext != null)
            {
                Type targetType = validationBindContext.TargetType;
                if (error == null)
                    validationErrors.AddRange(this.ValidateActivity(manager, bind, new BindValidationContext(targetType, validationBindContext.Access)));
            }

            if (error != null)
                validationErrors.Add(error);

            return validationErrors;
        }
        private ValidationErrorCollection ValidateMethod(ValidationManager manager, Activity activity, MethodBind bind, BindValidationContext validationBindContext)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();
            if ((validationBindContext.Access & AccessTypes.Write) != 0)
            {
                ValidationError error = new ValidationError(SR.GetString(SR.Error_HandlerReadOnly), ErrorNumbers.Error_HandlerReadOnly);
                error.PropertyName = GetFullPropertyName(manager);
                validationErrors.Add(error);
            }
            else
            {
                if (!TypeProvider.IsAssignable(typeof(Delegate), validationBindContext.TargetType))
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_TypeNotDelegate, validationBindContext.TargetType.FullName), ErrorNumbers.Error_TypeNotDelegate);
                    error.PropertyName = GetFullPropertyName(manager);
                    validationErrors.Add(error);
                }
                else
                {
                    string dsName = bind.Name;
                    Activity activityContext = Helpers.GetEnclosingActivity(activity);
                    Activity dataSourceActivity = activityContext;
                    if (dsName.IndexOf('.') != -1 && dataSourceActivity != null)
                        dataSourceActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out dsName);

                    if (dataSourceActivity == null)
                    {
                        ValidationError error = new ValidationError(SR.GetString(SR.Error_NoEnclosingContext, activity.Name), ErrorNumbers.Error_NoEnclosingContext);
                        error.PropertyName = GetFullPropertyName(manager) + ".Name";
                        validationErrors.Add(error);
                    }
                    else
                    {
                        string message = string.Empty;
                        int errorNumber = -1;
                        System.Type resolvedType = Helpers.GetDataSourceClass(dataSourceActivity, manager);
                        if (resolvedType == null)
                        {
                            message = SR.GetString(SR.Error_TypeNotResolvedInMethodName, GetFullPropertyName(manager) + ".Name");
                            errorNumber = ErrorNumbers.Error_TypeNotResolvedInMethodName;
                        }
                        else
                        {
                            try
                            {
                                ValidationHelpers.ValidateIdentifier(manager, dsName);
                            }
                            catch (Exception e)
                            {
                                validationErrors.Add(new ValidationError(e.Message, ErrorNumbers.Error_InvalidIdentifier));
                            }

                            // get the invoke method
                            MethodInfo invokeMethod = validationBindContext.TargetType.GetMethod("Invoke");
                            if (invokeMethod == null)
                                throw new Exception(SR.GetString(SR.Error_DelegateNoInvoke, validationBindContext.TargetType.FullName));

                            // resolve the method
                            List<Type> paramTypes = new List<Type>();
                            foreach (ParameterInfo paramInfo in invokeMethod.GetParameters())
                                paramTypes.Add(paramInfo.ParameterType);

                            MethodInfo methodInfo = Helpers.GetMethodExactMatch(resolvedType, dsName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, paramTypes.ToArray(), null);
                            if (methodInfo == null)
                            {
                                if (resolvedType.GetMethod(dsName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy) != null)
                                {
                                    message = SR.GetString(SR.Error_MethodSignatureMismatch, GetFullPropertyName(manager) + ".Name");
                                    errorNumber = ErrorNumbers.Error_MethodSignatureMismatch;
                                }
                                else
                                {
                                    message = SR.GetString(SR.Error_MethodNotExists, GetFullPropertyName(manager) + ".Name", bind.Name);
                                    errorNumber = ErrorNumbers.Error_MethodNotExists;
                                }
                            }
                            // 





                            else if (!invokeMethod.ReturnType.Equals(methodInfo.ReturnType))
                            {
                                message = SR.GetString(SR.Error_MethodReturnTypeMismatch, GetFullPropertyName(manager), invokeMethod.ReturnType.FullName);
                                errorNumber = ErrorNumbers.Error_MethodReturnTypeMismatch;
                            }
                        }
                        if (message.Length > 0)
                        {
                            ValidationError error = new ValidationError(message, errorNumber);
                            error.PropertyName = GetFullPropertyName(manager) + ".Path";
                            validationErrors.Add(error);
                        }
                    }
                }
            }
            return validationErrors;
        }
 private ValidationErrorCollection ValidateField(ValidationManager manager, Activity activity, FieldBind bind, BindValidationContext validationContext)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection();
     string name = bind.Name;
     Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
     if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
     {
         enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
     }
     if (enclosingActivity == null)
     {
         ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130) {
             PropertyName = base.GetFullPropertyName(manager) + ".Name"
         };
         errors.Add(error);
         return errors;
     }
     ValidationError item = null;
     Type dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);
     if (dataSourceClass == null)
     {
         item = new ValidationError(SR.GetString("Error_TypeNotResolvedInFieldName", new object[] { "Name" }), 0x11f) {
             PropertyName = base.GetFullPropertyName(manager)
         };
     }
     else
     {
         FieldInfo field = dataSourceClass.GetField(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
         if (field == null)
         {
             item = new ValidationError(SR.GetString("Error_FieldNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x120) {
                 PropertyName = base.GetFullPropertyName(manager)
             };
         }
         else if (field.FieldType == null)
         {
             item = new ValidationError(SR.GetString("Error_FieldTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 290) {
                 PropertyName = base.GetFullPropertyName(manager)
             };
         }
         else
         {
             MemberInfo memberInfo = field;
             if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, field.FieldType, validationContext.Access)))
             {
                 item = new ValidationError(SR.GetString("Error_FieldTypeMismatch", new object[] { base.GetFullPropertyName(manager), field.FieldType.FullName, validationContext.TargetType.FullName }), 0x13f) {
                     PropertyName = base.GetFullPropertyName(manager)
                 };
             }
             else if (!string.IsNullOrEmpty(bind.Path))
             {
                 memberInfo = MemberBind.GetMemberInfo(field.FieldType, bind.Path);
                 if (memberInfo == null)
                 {
                     item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300) {
                         PropertyName = base.GetFullPropertyName(manager) + ".Path"
                     };
                 }
                 else
                 {
                     using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                     {
                         if (WorkflowCompilationContext.Current.CheckTypes)
                         {
                             item = MemberBind.ValidateTypesInPath(field.FieldType, bind.Path);
                             if (item != null)
                             {
                                 item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                             }
                         }
                     }
                     if (item == null)
                     {
                         Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                         if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                         {
                             item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141) {
                                 PropertyName = base.GetFullPropertyName(manager) + ".Path"
                             };
                         }
                     }
                 }
             }
             if (item == null)
             {
                 if (memberInfo is PropertyInfo)
                 {
                     PropertyInfo info3 = memberInfo as PropertyInfo;
                     if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                     {
                         item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142) {
                             PropertyName = base.GetFullPropertyName(manager) + ".Path"
                         };
                     }
                     else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                     {
                         item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143) {
                             PropertyName = base.GetFullPropertyName(manager) + ".Path"
                         };
                     }
                 }
                 else if (memberInfo is FieldInfo)
                 {
                     FieldInfo info4 = memberInfo as FieldInfo;
                     if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                     {
                         item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145) {
                             PropertyName = base.GetFullPropertyName(manager) + ".Path"
                         };
                     }
                 }
             }
         }
     }
     if (item != null)
     {
         errors.Add(item);
     }
     return errors;
 }
 private ValidationErrorCollection ValidateBindProperty(ValidationManager manager, Activity activity, PropertyBind bind, BindValidationContext validationContext)
 {
     ValidationErrorCollection errors = new ValidationErrorCollection();
     string name = bind.Name;
     Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
     Activity refActivity = enclosingActivity;
     if ((name.IndexOf('.') != -1) && (refActivity != null))
     {
         refActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
     }
     if (refActivity == null)
     {
         ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130) {
             PropertyName = base.GetFullPropertyName(manager) + ".Name"
         };
         errors.Add(error);
         return errors;
     }
     ValidationError item = null;
     PropertyInfo property = null;
     Type activityType = null;
     if (property == null)
     {
         activityType = BindValidatorHelper.GetActivityType(manager, refActivity);
         if (activityType != null)
         {
             property = activityType.GetProperty(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
         }
     }
     if (activityType == null)
     {
         item = new ValidationError(SR.GetString("Error_TypeNotResolvedInPropertyName", new object[] { "Name" }), 0x163) {
             PropertyName = base.GetFullPropertyName(manager)
         };
     }
     else if (property == null)
     {
         item = new ValidationError(SR.GetString("Error_PropertyNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x164) {
             PropertyName = base.GetFullPropertyName(manager)
         };
     }
     else if (!property.CanRead)
     {
         item = new ValidationError(SR.GetString("Error_PropertyReferenceNoGetter", new object[] { base.GetFullPropertyName(manager), name }), 360) {
             PropertyName = base.GetFullPropertyName(manager)
         };
     }
     else if (property.GetGetMethod() == null)
     {
         item = new ValidationError(SR.GetString("Error_PropertyReferenceGetterNoAccess", new object[] { base.GetFullPropertyName(manager), name }), 0x60a) {
             PropertyName = base.GetFullPropertyName(manager)
         };
     }
     else if (((refActivity != enclosingActivity) && !property.GetGetMethod().IsAssembly) && !property.GetGetMethod().IsPublic)
     {
         item = new ValidationError(SR.GetString("Error_PropertyNotAccessible", new object[] { base.GetFullPropertyName(manager), name }), 0x165) {
             PropertyName = base.GetFullPropertyName(manager)
         };
     }
     else if (property.PropertyType == null)
     {
         item = new ValidationError(SR.GetString("Error_PropertyTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 0x166) {
             PropertyName = base.GetFullPropertyName(manager)
         };
     }
     else
     {
         MemberInfo memberInfo = property;
         if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, property.PropertyType, validationContext.Access)))
         {
             item = new ValidationError(SR.GetString("Error_PropertyTypeMismatch", new object[] { base.GetFullPropertyName(manager), property.PropertyType.FullName, validationContext.TargetType.FullName }), 0x167) {
                 PropertyName = base.GetFullPropertyName(manager)
             };
         }
         else if (!string.IsNullOrEmpty(bind.Path))
         {
             memberInfo = MemberBind.GetMemberInfo(property.PropertyType, bind.Path);
             if (memberInfo == null)
             {
                 item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300) {
                     PropertyName = base.GetFullPropertyName(manager) + ".Path"
                 };
             }
             else
             {
                 using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                 {
                     if (WorkflowCompilationContext.Current.CheckTypes)
                     {
                         item = MemberBind.ValidateTypesInPath(property.PropertyType, bind.Path);
                         if (item != null)
                         {
                             item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                         }
                     }
                 }
                 if (item == null)
                 {
                     Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                     if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                     {
                         item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141) {
                             PropertyName = base.GetFullPropertyName(manager) + ".Path"
                         };
                     }
                 }
             }
         }
         if (item == null)
         {
             if (memberInfo is PropertyInfo)
             {
                 PropertyInfo info3 = memberInfo as PropertyInfo;
                 if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                 {
                     item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142) {
                         PropertyName = base.GetFullPropertyName(manager) + ".Path"
                     };
                 }
                 else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                 {
                     item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143) {
                         PropertyName = base.GetFullPropertyName(manager) + ".Path"
                     };
                 }
             }
             else if (memberInfo is FieldInfo)
             {
                 FieldInfo info4 = memberInfo as FieldInfo;
                 if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                 {
                     item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145) {
                         PropertyName = base.GetFullPropertyName(manager) + ".Path"
                     };
                 }
             }
         }
     }
     if (item != null)
     {
         errors.Add(item);
     }
     return errors;
 }
Example #15
0
        private ValidationErrorCollection ValidateActivity(ValidationManager manager, ActivityBind bind, BindValidationContext validationContext)
        {
            ValidationError           item   = null;
            ValidationErrorCollection errors = new ValidationErrorCollection();
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
            }
            Activity request = Helpers.ParseActivityForBind(activity, bind.Name);

            if (request == null)
            {
                item = bind.Name.StartsWith("/", StringComparison.Ordinal) ? new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128) : new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129);
                item.PropertyName = base.GetFullPropertyName(manager) + ".Name";
            }
            else if ((bind.Path == null) || (bind.Path.Length == 0))
            {
                item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
            }
            else
            {
                if (!bind.Name.StartsWith("/", StringComparison.Ordinal) && !ValidationHelpers.IsActivitySourceInOrder(request, activity))
                {
                    item = new ValidationError(SR.GetString("Error_BindActivityReference", new object[] { request.QualifiedName, activity.QualifiedName }), 0x12a, true)
                    {
                        PropertyName = base.GetFullPropertyName(manager) + ".Name"
                    };
                }
                IDesignerHost          service = manager.GetService(typeof(IDesignerHost)) as IDesignerHost;
                WorkflowDesignerLoader loader  = manager.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                if ((service != null) && (loader != null))
                {
                    Type srcType = null;
                    if (service.RootComponent == request)
                    {
                        ITypeProvider provider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                        if (provider == null)
                        {
                            throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                        }
                        srcType = provider.GetType(service.RootComponentClassName);
                    }
                    else
                    {
                        request.GetType();
                    }
                    if (srcType != null)
                    {
                        MemberInfo memberInfo = MemberBind.GetMemberInfo(srcType, bind.Path);
                        if ((memberInfo == null) || ((memberInfo is PropertyInfo) && !(memberInfo as PropertyInfo).CanRead))
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else
                        {
                            Type memberType = null;
                            if (memberInfo is FieldInfo)
                            {
                                memberType = ((FieldInfo)memberInfo).FieldType;
                            }
                            else if (memberInfo is PropertyInfo)
                            {
                                memberType = ((PropertyInfo)memberInfo).PropertyType;
                            }
                            else if (memberInfo is EventInfo)
                            {
                                memberType = ((EventInfo)memberInfo).EventHandlerType;
                            }
                            if (!DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType))
                                {
                                    item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                                else
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName }), 0x12d)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                    }
                }
                else
                {
                    MemberInfo info2 = MemberBind.GetMemberInfo(request.GetType(), bind.Path);
                    if ((info2 == null) || ((info2 is PropertyInfo) && !(info2 as PropertyInfo).CanRead))
                    {
                        item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300)
                        {
                            PropertyName = base.GetFullPropertyName(manager) + ".Path"
                        };
                    }
                    else
                    {
                        DependencyProperty dependencyProperty = DependencyProperty.FromName(info2.Name, info2.DeclaringType);
                        object             obj2 = BindHelpers.ResolveActivityPath(request, bind.Path);
                        if (obj2 == null)
                        {
                            Type fromType = null;
                            if (info2 is FieldInfo)
                            {
                                fromType = ((FieldInfo)info2).FieldType;
                            }
                            else if (info2 is PropertyInfo)
                            {
                                fromType = ((PropertyInfo)info2).PropertyType;
                            }
                            else if (info2 is EventInfo)
                            {
                                fromType = ((EventInfo)info2).EventHandlerType;
                            }
                            if (!TypeProvider.IsAssignable(typeof(ActivityBind), fromType) && !DoesTargetTypeMatch(validationContext.TargetType, fromType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(info2.DeclaringType))
                                {
                                    item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                                else
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, fromType.FullName, validationContext.TargetType.FullName }), 0x12d)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                        else if ((obj2 is ActivityBind) && (request.Parent != null))
                        {
                            ActivityBind         bind2   = obj2 as ActivityBind;
                            bool                 flag    = false;
                            BindRecursionContext context = manager.Context[typeof(BindRecursionContext)] as BindRecursionContext;
                            if (context == null)
                            {
                                context = new BindRecursionContext();
                                manager.Context.Push(context);
                                flag = true;
                            }
                            if (context.Contains(activity, bind))
                            {
                                item = new ValidationError(SR.GetString("Bind_ActivityDataSourceRecursionDetected"), 0x12f)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                            else
                            {
                                context.Add(activity, bind);
                                PropertyValidationContext propertyValidationContext = null;
                                if (dependencyProperty != null)
                                {
                                    propertyValidationContext = new PropertyValidationContext(request, dependencyProperty);
                                }
                                else
                                {
                                    propertyValidationContext = new PropertyValidationContext(request, info2 as PropertyInfo, info2.Name);
                                }
                                errors.AddRange(ValidationHelpers.ValidateProperty(manager, request, bind2, propertyValidationContext, validationContext));
                            }
                            if (flag)
                            {
                                manager.Context.Pop();
                            }
                        }
                        else if ((validationContext.TargetType != null) && !DoesTargetTypeMatch(validationContext.TargetType, obj2.GetType(), validationContext.Access))
                        {
                            item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, obj2.GetType().FullName, validationContext.TargetType.FullName }), 0x12d)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }