Пример #1
0
        public void Attributes_Cities_Entity_Bindable_On_Property_TwoWay()
        {
            BindableAttribute attr = ExpectPropertyAttribute <BindableAttribute>(typeof(City), "ZoneID");

            Assert.AreEqual(true, attr.Bindable);
            Assert.AreEqual(BindingDirection.TwoWay, attr.Direction);
        }
Пример #2
0
        public void Attributes_Cities_Entity_Bindable_On_Class()
        {
            BindableAttribute attr = ExpectTypeAttribute <BindableAttribute>(typeof(City));

            Assert.AreEqual(true, attr.Bindable);
            Assert.AreEqual(BindingDirection.OneWay, attr.Direction);
        }
Пример #3
0
        public void Attributes_Cities_Entity_Bindable_On_Property()
        {
            BindableAttribute attr = ExpectPropertyAttribute <BindableAttribute>(typeof(City), "ZoneName");

            Assert.AreEqual(false, attr.Bindable);
            Assert.AreEqual(BindingDirection.OneWay, attr.Direction);
        }
Пример #4
0
        public void GetAttribute_returns_correct_value()
        {
            var expected = new BindableAttribute(true, BindingDirection.OneWay);
            var res      = typeof(ClassWithAttributesAndDefaultAttribute).GetAttribute <BindableAttribute>();

            res.ShouldBeEquivalentTo(expected);
        }
Пример #5
0
        /// <summary>
        /// Determines whether the specified property has a <see cref="BindableAttribute"/> set, and is not a MEF imported property.
        /// </summary>
        public static bool IsBindableDesignProperty(this PropertyDescriptor descriptor)
        {
            Guard.NotNull(() => descriptor, descriptor);

            BindableAttribute attribute = descriptor.Attributes.OfType <BindableAttribute>().FirstOrDefault();

            return(((attribute == null) || attribute.Bindable) && !descriptor.IsImported());
        }
Пример #6
0
        public void Constructor_builds_correct_object(string name, bool bindable, BindingDirection direction)
        {
            var expected                = new BindableAttribute(bindable, direction);
            var propertyInfo            = typeof(ClassWithAttributes).GetProperty(name);
            var propertyInfoDescription = new PropertyInfoDescription(propertyInfo);

            propertyInfoDescription.Attribute.ShouldBeEquivalentTo(expected);
        }
Пример #7
0
        public void GetAttribute_returns_attribute(string name, bool bindable, BindingDirection direction)
        {
            var expected     = new BindableAttribute(bindable, direction);
            var propertyInfo = typeof(ClassWithAttributes).GetProperty(name);
            var attribute    = propertyInfo.GetAttribute <BindableAttribute>();

            attribute.Should().BeEquivalentTo(expected);
        }
Пример #8
0
        public void Ctor_BindableSupport_BindingDirection(BindableSupport support, BindingDirection direction, bool expectedBindable)
        {
            var attribute = new BindableAttribute(support, direction);

            Assert.Equal(expectedBindable, attribute.Bindable);
            Assert.Equal(direction, attribute.Direction);

            Assert.Equal(!expectedBindable || support == BindableSupport.Default, attribute.IsDefaultAttribute());
        }
Пример #9
0
        public void Ctor_Bindable(bool bindable)
        {
            var attribute = new BindableAttribute(bindable);

            Assert.Equal(bindable, attribute.Bindable);
            Assert.Equal(BindingDirection.OneWay, attribute.Direction);

            Assert.Equal(!bindable, attribute.IsDefaultAttribute());
        }
Пример #10
0
        public void Ctor_Bindable_BindingDirection(bool bindable, BindingDirection direction)
        {
            var attribute = new BindableAttribute(bindable, direction);

            Assert.Equal(bindable, attribute.Bindable);
            Assert.Equal(direction, attribute.Direction);

            Assert.Equal(!bindable, attribute.IsDefaultAttribute());
        }
Пример #11
0
        public void Constructor_use_default_if_not_found(string name, bool bindable, BindingDirection direction)
        {
            var expected                = new BindableAttribute(bindable, direction);
            var defaultAttribute        = new BindableAttribute(false, BindingDirection.TwoWay);
            var propertyInfo            = typeof(ClassWithAttributes).GetProperty(name);
            var propertyInfoDescription = new PropertyInfoDescription(propertyInfo, defaultAttribute);

            propertyInfoDescription.Attribute.ShouldBeEquivalentTo(expected);
        }
        public void BindableSelection_NoUserServiceInDependencyResolver_ThrowsNullReferenceException()
        {
            mockContainerProvider = new Mock <IContainerProvider>();
            DependencyResolver.SetResolver(mockContainerProvider.Object);

            var attribute = new BindableAttribute("Role1");

            attribute.IsBindable();
        }
Пример #13
0
        public void No_Get_ReturnsExpected()
        {
            BindableAttribute attribute = BindableAttribute.No;

            Assert.Same(attribute, BindableAttribute.No);

            Assert.False(attribute.Bindable);
            Assert.Equal(BindingDirection.OneWay, attribute.Direction);
            Assert.True(attribute.IsDefaultAttribute());
        }
        public void CanGetEditorAttributeFromCollection()
        {
            BindableAttribute bindableAttribute = new BindableAttribute(false);
            EditorAttribute   editorAttribute   = new EditorAttribute();

            Attribute[]         attributes          = new Attribute[] { bindableAttribute, editorAttribute };
            AttributeCollection attributeCollection = new AttributeCollection(attributes);

            Assert.AreSame(editorAttribute, WixBindingTestsHelper.GetEditorAttribute(attributeCollection));
        }
Пример #15
0
        // Determine if two instances of this class are equal.
        public override bool Equals(Object obj)
        {
            BindableAttribute other = (obj as BindableAttribute);

            if (other != null)
            {
                return(bind == other.bind);
            }
            else
            {
                return(false);
            }
        }
Пример #16
0
        public static IEnumerable <object[]> Equals_TestData()
        {
            var attribute = new BindableAttribute(true, BindingDirection.OneWay);

            yield return(new object[] { attribute, attribute, true });

            yield return(new object[] { attribute, new BindableAttribute(true, BindingDirection.TwoWay), true });

            yield return(new object[] { attribute, new BindableAttribute(false, BindingDirection.OneWay), false });

            yield return(new object[] { attribute, new object(), false });

            yield return(new object[] { attribute, null, false });
        }
Пример #17
0
    protected void Method()
    {
        // <Snippet1>
        // Gets the attributes for the property.
        AttributeCollection attributes =
            TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

        // Checks to see if the property is bindable.
        BindableAttribute myAttribute = (BindableAttribute)attributes[typeof(BindableAttribute)];

        if (myAttribute.Bindable)
        {
            // Insert code here.
        }
        // </Snippet1>
    }
Пример #18
0
        public static BindingModeInfo GetDefaultBindingMode(DocumentNode targetNode, IPropertyId targetProperty, DataSchemaNodePath schemaPath)
        {
            BindingMode      mode             = (BindingMode)targetNode.TypeResolver.GetCapabilityValue(PlatformCapability.DefaultBindingMode);
            BindingDirection bindingDirection = (BindingDirection)targetNode.TypeResolver.GetCapabilityValue(PlatformCapability.DefaultBindingDirection);
            DependencyPropertyReferenceStep propertyReferenceStep = targetNode.TypeResolver.ResolveProperty(targetProperty) as DependencyPropertyReferenceStep;
            bool flag = false;

            if (schemaPath != null)
            {
                if (schemaPath.Node.IsReadOnly)
                {
                    flag = true;
                }
                else if (schemaPath.Node == schemaPath.Schema.Root)
                {
                    flag = !DataContextHelper.IsDataContextProperty(targetNode, (IPropertyId)propertyReferenceStep);
                }
            }
            if (flag)
            {
                if (mode == BindingMode.Default && bindingDirection == BindingDirection.TwoWay && (propertyReferenceStep != null && propertyReferenceStep.BindsTwoWayByDefault(targetNode.Type.RuntimeType)))
                {
                    return(new BindingModeInfo(BindingMode.OneWay, false));
                }
                if (schemaPath.IsCollection)
                {
                    return(new BindingModeInfo(mode, true));
                }
                return(new BindingModeInfo(BindingMode.OneWay, false));
            }
            if (bindingDirection == BindingDirection.TwoWay)
            {
                return(new BindingModeInfo(mode, true));
            }
            IProperty property = targetNode.TypeResolver.ResolveProperty(targetProperty);

            if (property != null)
            {
                BindableAttribute bindableAttribute = property.Attributes[typeof(BindableAttribute)] as BindableAttribute;
                if (bindableAttribute != null && bindableAttribute.Direction == BindingDirection.TwoWay)
                {
                    return(new BindingModeInfo(BindingMode.TwoWay, false));
                }
            }
            return(new BindingModeInfo(mode, true));
        }
        public void BindableSelection_IsNotBindableWithRoleUserDoesNotHave_Fails()
        {
            var attribute = new BindableAttribute("RoleUserDoesNotHave");

            Assert.IsFalse(attribute.IsBindable());
        }
        public void BindableSelection_IsBindableWithRoleUserHas_Validates()
        {
            var attribute = new BindableAttribute("Role1");

            Assert.IsTrue(attribute.IsBindable());
        }
        public void BindableSelection_IsBindableWithEmptyRole_Validates()
        {
            var attribute = new BindableAttribute(new string[] {});

            Assert.IsTrue(attribute.IsBindable());
        }
Пример #22
0
        protected static bool IsTwoWayBindable(BindableAttribute bindableAttribute)
        {
            var bindingDirectionIsTwoWay = bindableAttribute.Direction == BindingDirection.TwoWay;

            return(bindingDirectionIsTwoWay);
        }
Пример #23
0
        private void DiscoverObject()
        {
            this.displays.Clear();
            this.properties.Clear();
            this.bindables.Clear();
            this.bindings.Clear();
#if !SILVERLIGHT
            this.rules.Clear();
#endif
            this.controls.Clear();
            this.validations.Clear();

            if (this.CurrentItem == null)
            {
                return;
            }

            Type           dataType = this.CurrentItem.GetType();
            PropertyInfo[] properties;

            //Code for dynamic Types....

            /*var meta = this.CurrentItem as IDynamicMetaObjectProvider;
             * if (meta != null)
             * {
             *  List<PropertyInfo> tmpLst = new List<PropertyInfo>();
             *  var metaObject = meta.GetMetaObject(System.Linq.Expressions.Expression.Constant(this.CurrentItem));
             *  var membernames = metaObject.GetDynamicMemberNames();
             *  foreach (var membername in membernames)
             *  {
             *      var binder = Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, membername, dataType, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
             *      var callsite = CallSite<Func<CallSite, object, object>>.Create(binder);
             *      var item = callsite.Target(callsite, this.CurrentItem);
             *  }
             * }
             * else*/
            {
                properties = GetPropertyInfos(dataType);
            }

            BindableAttribute bindable = ((BindableAttribute[])dataType.GetCustomAttributes(typeof(System.ComponentModel.BindableAttribute), true)).FirstOrDefault();

            foreach (PropertyInfo property in properties)
            {
                BindableAttribute propBindable = ((BindableAttribute[])property.GetCustomAttributes(typeof(System.ComponentModel.BindableAttribute), true)).FirstOrDefault();

                // Check if Readable
                if (!property.CanRead)
                {
                    continue;
                }

                // Check if Bindable
                if ((bindable != null && !bindable.Bindable && propBindable == null) || (bindable != null && !bindable.Bindable && propBindable != null && !propBindable.Bindable) || (propBindable != null && !propBindable.Bindable))
                {
                    continue;
                }


                DisplayAttribute           propDisplay  = ((DisplayAttribute[])Attribute.GetCustomAttributes(property, typeof(DisplayAttribute), true)).FirstOrDefault();
                EditableAttribute          propEditable = ((EditableAttribute[])Attribute.GetCustomAttributes(property, typeof(EditableAttribute), true)).FirstOrDefault();
                List <ValidationAttribute> validations  = new List <ValidationAttribute>((ValidationAttribute[])Attribute.GetCustomAttributes(property, typeof(ValidationAttribute), true));

                if (propDisplay == null)
                {
                    propDisplay = new DisplayAttribute()
                    {
                        AutoGenerateField = true, Name = property.Name, ShortName = property.Name, Order = 10000, Prompt = null, GroupName = null, Description = null
                    }
                }
                ;
                if (propEditable == null)
                {
                    propEditable = new EditableAttribute(!this.DefaultReadOnly)
                    {
                        AllowInitialValue = true
                    }
                }
                ;

                bool setPrivate = true;
                if (property.GetSetMethod(true) != null)
                {
                    setPrivate = !property.GetSetMethod(true).IsPublic;
                }

                if (propDisplay.GetAutoGenerateField().HasValue&& !propDisplay.AutoGenerateField)
                {
                    continue;
                }

                if (PropertyDisplayInformations != null)
                {
                    var prpDisplay = PropertyDisplayInformations.FirstOrDefault(x => x.Name == property.Name);
                    if (prpDisplay == null || !prpDisplay.Visible)
                    {
                        continue;
                    }
                    propDisplay.Order = prpDisplay.Order;
                }


                if (bindable != null && propBindable == null)
                {
                    if ((!property.CanWrite || !propEditable.AllowEdit || setPrivate) && bindable.Direction == BindingDirection.TwoWay)
                    {
                        this.bindables.Add(property.Name, new BindableAttribute(true, BindingDirection.OneWay));
                    }
                    else
                    {
                        this.bindables.Add(property.Name, new BindableAttribute(true, bindable.Direction));
                    }
                }
                else if (propBindable != null)
                {
                    if ((!property.CanWrite || !propEditable.AllowEdit || setPrivate) && propBindable.Direction == BindingDirection.TwoWay)
                    {
                        this.bindables.Add(property.Name, new BindableAttribute(true, BindingDirection.OneWay));
                    }
                    else
                    {
                        this.bindables.Add(property.Name, new BindableAttribute(true, propBindable.Direction));
                    }
                }
                else
                {
                    if (!this.bindables.ContainsKey(property.Name))
                    {
                        if (!property.CanWrite || !propEditable.AllowEdit || setPrivate)
                        {
                            this.bindables.Add(property.Name, new BindableAttribute(true, BindingDirection.OneWay));
                        }
                        else
                        {
                            this.bindables.Add(property.Name, new BindableAttribute(true, BindingDirection.TwoWay));
                        }
                    }
                }

                if (!this.validations.ContainsKey(property.Name))
                {
                    this.validations.Add(property.Name, validations);
                    this.displays.Add(property.Name, propDisplay);
                    this.properties.Add(property.Name, property);
                }
            }
        }
Пример #24
0
 public PropertyInfoDescription(PropertyInfo propertyInfo, BindableAttribute defaultAttribute = null)
 {
     Attribute    = propertyInfo.GetAttribute <BindableAttribute>() ?? defaultAttribute;
     PropertyInfo = propertyInfo;
 }
Пример #25
0
        public void GetHashCode_Invoke_ReturnsBindableHashCode()
        {
            var attribute = new BindableAttribute(true);

            Assert.Equal(1, attribute.GetHashCode());
        }
Пример #26
0
 public void Equals_Object_ReturnsExpected(BindableAttribute attribute, object other, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(other));
 }
Пример #27
0
 private void BindingFormattingDialog_Load(object sender, EventArgs e)
 {
     this.inLoad = true;
     try
     {
         BindingTreeNode node6;
         this.dirty = false;
         Font       defaultFont = Control.DefaultFont;
         IUIService service     = null;
         if (this.bindings.BindableComponent.Site != null)
         {
             service = (IUIService)this.bindings.BindableComponent.Site.GetService(typeof(IUIService));
         }
         if (service != null)
         {
             defaultFont = (Font)service.Styles["DialogFont"];
         }
         this.Font = defaultFont;
         DesignerUtils.ApplyTreeViewThemeStyles(this.propertiesTreeView);
         if (this.propertiesTreeView.ImageList == null)
         {
             ImageList list = new ImageList();
             list.Images.Add(BoundBitmap);
             list.Images.Add(UnboundBitmap);
             this.propertiesTreeView.ImageList = list;
         }
         BindingTreeNode node  = null;
         BindingTreeNode node2 = null;
         string          name  = null;
         string          str2  = null;
         foreach (Attribute attribute in TypeDescriptor.GetAttributes(this.bindings.BindableComponent))
         {
             if (attribute is DefaultBindingPropertyAttribute)
             {
                 name = ((DefaultBindingPropertyAttribute)attribute).Name;
                 break;
             }
             if (attribute is DefaultPropertyAttribute)
             {
                 str2 = ((DefaultPropertyAttribute)attribute).Name;
             }
         }
         this.propertiesTreeView.Nodes.Clear();
         TreeNode node3 = new TreeNode(System.Design.SR.GetString("BindingFormattingDialogCommonTreeNode"));
         TreeNode node4 = new TreeNode(System.Design.SR.GetString("BindingFormattingDialogAllTreeNode"));
         this.propertiesTreeView.Nodes.Add(node3);
         this.propertiesTreeView.Nodes.Add(node4);
         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this.bindings.BindableComponent);
         for (int i = 0; i < properties.Count; i++)
         {
             if (!properties[i].IsReadOnly)
             {
                 BindableAttribute  attribute2 = (BindableAttribute)properties[i].Attributes[typeof(BindableAttribute)];
                 BrowsableAttribute attribute3 = (BrowsableAttribute)properties[i].Attributes[typeof(BrowsableAttribute)];
                 if (((attribute3 == null) || attribute3.Browsable) || ((attribute2 != null) && attribute2.Bindable))
                 {
                     BindingTreeNode node5 = new BindingTreeNode(properties[i].Name)
                     {
                         Binding = this.FindBinding(properties[i].Name)
                     };
                     if (node5.Binding != null)
                     {
                         node5.FormatType = FormatControl.FormatTypeStringFromFormatString(node5.Binding.FormatString);
                     }
                     else
                     {
                         node5.FormatType = System.Design.SR.GetString("BindingFormattingDialogFormatTypeNoFormatting");
                     }
                     if ((attribute2 != null) && attribute2.Bindable)
                     {
                         node3.Nodes.Add(node5);
                     }
                     else
                     {
                         node4.Nodes.Add(node5);
                     }
                     if (((node == null) && !string.IsNullOrEmpty(name)) && (string.Compare(properties[i].Name, name, false, CultureInfo.CurrentCulture) == 0))
                     {
                         node = node5;
                     }
                     else if (((node2 == null) && !string.IsNullOrEmpty(str2)) && (string.Compare(properties[i].Name, str2, false, CultureInfo.CurrentCulture) == 0))
                     {
                         node2 = node5;
                     }
                 }
             }
         }
         node3.Expand();
         node4.Expand();
         this.propertiesTreeView.Sort();
         if (node != null)
         {
             node6 = node;
         }
         else if (node2 != null)
         {
             node6 = node2;
         }
         else if (node3.Nodes.Count > 0)
         {
             node6 = FirstNodeInAlphabeticalOrder(node3.Nodes) as BindingTreeNode;
         }
         else if (node4.Nodes.Count > 0)
         {
             node6 = FirstNodeInAlphabeticalOrder(node4.Nodes) as BindingTreeNode;
         }
         else
         {
             node6 = null;
         }
         this.propertiesTreeView.SelectedNode = node6;
         if (node6 != null)
         {
             node6.EnsureVisible();
         }
         this.dataSourcePicker.PropertyName   = node6.Text;
         this.dataSourcePicker.Binding        = (node6 != null) ? node6.Binding : null;
         this.dataSourcePicker.Enabled        = true;
         this.dataSourcePicker.OwnerComponent = this.bindings.BindableComponent;
         this.dataSourcePicker.DefaultDataSourceUpdateMode = this.bindings.DefaultDataSourceUpdateMode;
         if ((node6 != null) && (node6.Binding != null))
         {
             this.bindingUpdateDropDown.Enabled      = true;
             this.bindingUpdateDropDown.SelectedItem = node6.Binding.DataSourceUpdateMode;
             this.updateModeLabel.Enabled            = true;
             this.formatControl1.Enabled             = true;
             this.formatControl1.FormatType          = node6.FormatType;
             this.formatControl1.FormatTypeItem.PushFormatStringIntoFormatType(node6.Binding.FormatString);
             if (node6.Binding.NullValue != null)
             {
                 this.formatControl1.NullValue = node6.Binding.NullValue.ToString();
             }
             else
             {
                 this.formatControl1.NullValue = string.Empty;
             }
         }
         else
         {
             this.bindingUpdateDropDown.Enabled      = false;
             this.bindingUpdateDropDown.SelectedItem = this.bindings.DefaultDataSourceUpdateMode;
             this.updateModeLabel.Enabled            = false;
             this.formatControl1.Enabled             = false;
             this.formatControl1.FormatType          = string.Empty;
         }
         this.formatControl1.Dirty   = false;
         this.currentBindingTreeNode = this.propertiesTreeView.SelectedNode as BindingTreeNode;
     }
     finally
     {
         this.inLoad = false;
     }
 }