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

            ValidationErrorCollection validationErrors = base.Validate(manager, obj);
            DependencyObject          dependencyObject = obj as DependencyObject;

            if (dependencyObject == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(DependencyObject).FullName), "obj");
            }

            ArrayList allProperties = new ArrayList();

            // Validate all the settable dependency properties
            // attached property can not be found through the call to DependencyProperty.FromType()
            foreach (DependencyProperty prop in DependencyProperty.FromType(dependencyObject.GetType()))
            {
                // This property is attached to some other object.  We should not validate it here
                // because the context is wrong.
                if (!prop.IsAttached)
                {
                    allProperties.Add(prop);
                }
            }
            //


            foreach (DependencyProperty prop in dependencyObject.MetaDependencyProperties)
            {
                if (prop.IsAttached)
                {
                    if (obj.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance) == null)
                    {
                        allProperties.Add(prop);
                    }
                }
            }

            foreach (DependencyProperty prop in allProperties)
            {
                object[]         validationVisibilityAtrributes = prop.DefaultMetadata.GetAttributes(typeof(ValidationOptionAttribute));
                ValidationOption validationVisibility           = (validationVisibilityAtrributes.Length > 0) ? ((ValidationOptionAttribute)validationVisibilityAtrributes[0]).ValidationOption : ValidationOption.Optional;
                if (validationVisibility != ValidationOption.None)
                {
                    validationErrors.AddRange(ValidateDependencyProperty(dependencyObject, prop, manager));
                }
            }

            return(validationErrors);
        }
Beispiel #2
0
        protected override void PreFilterProperties(IDictionary properties)
        {
            base.PreFilterProperties(properties);

            if (this.targetWorkflowType != null)
            {
                try
                {
                    foreach (PropertyInfo parameterProperty in this.targetWorkflowType.GetProperties())
                    {
                        if (!parameterProperty.CanWrite)
                        {
                            continue;
                        }

                        if (parameterProperty.DeclaringType == typeof(DependencyObject) ||
                            parameterProperty.DeclaringType == typeof(Activity) ||
                            parameterProperty.DeclaringType == typeof(CompositeActivity) ||
                            ((parameterProperty.DeclaringType == Type.GetType(DesignerHelpers.SequentialWorkflowTypeRef) ||
                              parameterProperty.DeclaringType == Type.GetType(DesignerHelpers.StateMachineWorkflowTypeRef)) &&
                             string.Equals(parameterProperty.Name, "DynamicUpdateCondition", StringComparison.Ordinal)))
                        {
                            continue;
                        }

                        bool ignoreProperty       = false;
                        Type dependencyObjectType = this.targetWorkflowType;
                        while (dependencyObjectType != null && dependencyObjectType is DesignTimeType)
                        {
                            dependencyObjectType = dependencyObjectType.BaseType;
                        }

                        if (dependencyObjectType != null)
                        {
                            foreach (DependencyProperty dependencyProperty in DependencyProperty.FromType(dependencyObjectType))
                            {
                                if (dependencyProperty.Name == parameterProperty.Name && dependencyProperty.DefaultMetadata.IsMetaProperty)
                                {
                                    ignoreProperty = true;
                                    break;
                                }
                            }
                        }

                        if (!ignoreProperty)
                        {
                            PropertyDescriptor prop = new ParameterInfoBasedPropertyDescriptor(Type.GetType(InvokeWorkflowRef), parameterProperty.Name, parameterProperty.PropertyType, ReservedParameterNames.Contains(parameterProperty.Name), DesignOnlyAttribute.Yes);
                            properties[prop.Name] = prop;
                        }
                    }
                }
                catch (MissingMemberException)
                {
                    // targetServiceType has no default CTor, ignore
                }
            }
        }
Beispiel #3
0
        public void Test1()
        {
            DependencyProperty dp = DependencyProperty.Register("From", typeof(string),
                                                                typeof(ClassProp), new PropertyMetadata("*****@*****.**"));

            Assert.AreEqual(false, dp.IsAttached, "C1#1");
            Assert.AreEqual(false, dp.IsEvent, "C1#2");
            Assert.AreEqual("From", dp.Name, "C1#3");

            Assert.AreEqual(typeof(ClassProp), dp.OwnerType, "C1#4");
            Assert.AreEqual(typeof(string), dp.PropertyType, "C1#5");
            Assert.AreEqual(null, dp.ValidatorType, "C1#6");

            IList <DependencyProperty> list = DependencyProperty.FromType(typeof(DependencyPropertyTest));

            Assert.AreEqual(0, list.Count, "C1#7");
            Assert.AreEqual("From", dp.ToString(), "C1#8");
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            ValidationErrorCollection errors           = base.Validate(manager, obj);
            DependencyObject          dependencyObject = obj as DependencyObject;

            if (dependencyObject == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(DependencyObject).FullName }), "obj");
            }
            ArrayList list = new ArrayList();

            foreach (DependencyProperty property in DependencyProperty.FromType(dependencyObject.GetType()))
            {
                if (!property.IsAttached)
                {
                    list.Add(property);
                }
            }
            foreach (DependencyProperty property2 in dependencyObject.MetaDependencyProperties)
            {
                if (property2.IsAttached && (obj.GetType().GetProperty(property2.Name, BindingFlags.Public | BindingFlags.Instance) == null))
                {
                    list.Add(property2);
                }
            }
            foreach (DependencyProperty property3 in list)
            {
                object[] attributes = property3.DefaultMetadata.GetAttributes(typeof(ValidationOptionAttribute));
                if (((attributes.Length > 0) ? ((ValidationOptionAttribute)attributes[0]).ValidationOption : ValidationOption.Optional) != ValidationOption.None)
                {
                    errors.AddRange(this.ValidateDependencyProperty(dependencyObject, property3, manager));
                }
            }
            return(errors);
        }
Beispiel #5
0
 protected override void PreFilterProperties(IDictionary properties)
 {
     base.PreFilterProperties(properties);
     if (this.targetWorkflowType != null)
     {
         try
         {
             foreach (PropertyInfo info in this.targetWorkflowType.GetProperties())
             {
                 if (((!info.CanWrite || (info.DeclaringType == typeof(DependencyObject))) || ((info.DeclaringType == typeof(Activity)) || (info.DeclaringType == typeof(CompositeActivity)))) || (((info.DeclaringType == Type.GetType("System.Workflow.Activities.SequentialWorkflowActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")) || (info.DeclaringType == Type.GetType("System.Workflow.Activities.StateMachineWorkflowActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"))) && string.Equals(info.Name, "DynamicUpdateCondition", StringComparison.Ordinal)))
                 {
                     continue;
                 }
                 bool flag = false;
                 Type targetWorkflowType = this.targetWorkflowType;
                 while ((targetWorkflowType != null) && (targetWorkflowType is DesignTimeType))
                 {
                     targetWorkflowType = targetWorkflowType.BaseType;
                 }
                 if (targetWorkflowType != null)
                 {
                     foreach (DependencyProperty property in DependencyProperty.FromType(targetWorkflowType))
                     {
                         if ((property.Name == info.Name) && property.DefaultMetadata.IsMetaProperty)
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 if (!flag)
                 {
                     PropertyDescriptor descriptor = new ParameterInfoBasedPropertyDescriptor(Type.GetType("System.Workflow.Activities.InvokeWorkflowActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"), info.Name, info.PropertyType, ReservedParameterNames.Contains(info.Name), new Attribute[] { DesignOnlyAttribute.Yes });
                     properties[descriptor.Name] = descriptor;
                 }
             }
         }
         catch (MissingMemberException)
         {
         }
     }
 }