Example #1
0
        public void RemoveExistingTests(int index)
        {
            var propertyDescriptors = new PropertyDescriptor[]
            {
                new MockPropertyDescriptor("propertyDescriptor1"),
                new MockPropertyDescriptor("propertyDescriptor2"),
                new MockPropertyDescriptor("propertyDescriptor3"),
                new MockPropertyDescriptor("propertyDescriptor4"),
                new MockPropertyDescriptor("propertyDescriptor5"),
                new MockPropertyDescriptor("propertyDescriptor6"),
                new MockPropertyDescriptor("propertyDescriptor7"),
                new MockPropertyDescriptor("propertyDescriptor8"),
                new MockPropertyDescriptor("propertyDescriptor9")
            };

            // Must send in a copy to the constructor as the array itself is manipulated
            var collection = new PropertyDescriptorCollection(propertyDescriptors.ToArray());

            Assert.True(index >= 0 && index < propertyDescriptors.Length, $"Index '{index}' is out of bounds");

            collection.Remove(propertyDescriptors[index]);

            for (int i = 0; i < propertyDescriptors.Length; i++)
            {
                if (i == index)
                {
                    Assert.False(collection.Contains(propertyDescriptors[index]), "Should have removed descriptor");
                }
                else
                {
                    Assert.True(collection.Contains(propertyDescriptors[i]), $"Descriptor should be in collection: {i}");
                }
            }
        }
        public void can_create()
        {
            var property0 = PropertyDescriptor.For(typeof(DecoratedType).GetProperty("Property0"));
            var property1 = PropertyDescriptor.For(typeof(DecoratedType).GetProperty("Property1"));
            var collection = new PropertyDescriptorCollection(new[] { property0, property1 });

            Assert.True(collection.Contains(property0));
            Assert.True(collection.Contains(property1));
            Assert.Equal(2, collection.Count);
            Assert.Equal(0, collection.IndexOf(property0));
            Assert.Equal(1, collection.IndexOf(property1));
        }
Example #3
0
        public static void ExpectException <T>(ExceptionTriggerCallback exceptionTrigger, T expectedException, string resourceId, WpfBinaries targetBinary) where T : Exception
        {
            ExpectException(exceptionTrigger, delegate(T caughtException)
            {
                if (!String.IsNullOrEmpty(resourceId) && !Exceptions.CompareMessage(caughtException.Message, resourceId, targetBinary))
                {
                    throw new TestValidationException("Expected Message: " + Exceptions.GetMessage(resourceId, targetBinary) + ", Actual Message: " + caughtException.Message);
                }

                PropertyDescriptorCollection baseClassProperties = TypeDescriptor.GetProperties(typeof(Exception));
                PropertyDescriptorCollection subClassProperties  = TypeDescriptor.GetProperties(typeof(T));

                foreach (PropertyDescriptor property in subClassProperties)
                {
                    if (!baseClassProperties.Contains(property))
                    {
                        if (!Object.Equals(property.GetValue(caughtException), property.GetValue(expectedException)))
                        {
                            throw new TestValidationException("Property Name: " + property.Name + ", Expected Value: " + property.GetValue(expectedException) + ", Actual Value: " + property.GetValue(caughtException));
                        }
                    }
                }

                return;
            });
        }
Example #4
0
        public virtual Boolean HasProperty(PropertyDescriptor property)
        {
            PropertyDescriptorCollection properties = _instanceProperties ?? _layerTypeProperties;

            return(properties.Contains(property) || (_propertyValues != null &&
                                                     _propertyValues.ContainsKey(property)));
        }
Example #5
0
        protected virtual void SetPropertyValueInternal(PropertyDescriptor property, Object value)
        {
            PropertyDescriptorCollection classProperties = GetClassProperties();

            if (classProperties.Contains(property))
            {
                String propertyName = property.Name;

                SetObjectProperty(propertyName, value);
            }
            else if (_instanceProperties.Contains(property))
            {
                if (_propertyValues == null)
                {
                    _propertyValues = new Dictionary <PropertyDescriptor, Object>();
                }

                _propertyValues[property] = value;
            }
            else
            {
                throw new InvalidOperationException("Property doesn't exist on this layer: " +
                                                    property.Name);
            }
        }
Example #6
0
        protected virtual Object GetPropertyValueInternal(PropertyDescriptor property)
        {
            if (_layerTypeProperties.Contains(property))
            {
                String propertyName = property.Name;

                if (LayerNameProperty.Name.Equals(propertyName))
                {
                    return(_layerName);
                }

                if (CoordinateTransformationProperty.Name.Equals(propertyName))
                {
                    return(CoordinateTransformation);
                }

                if (AsyncQueryProperty.Name.Equals(propertyName))
                {
                    return(AsyncQuery);
                }

                if (EnabledProperty.Name.Equals(propertyName))
                {
                    return(Enabled);
                }

                if (StyleProperty.Name.Equals(propertyName))
                {
                    return(Style);
                }
            }

            if (_instanceProperties.Contains(property))
            {
                Object value;

                return(_propertyValues != null && _propertyValues.TryGetValue(property, out value)
                           ? value
                           : null);
            }

            throw new InvalidOperationException("Property doesn't exist on this layer: " +
                                                property.Name);
        }
        private void AddIdPropertyIfAvailableTo(PropertyDescriptorCollection modelProperties, ModelBindingContext bindingContext)
        {
            PropertyDescriptor idProperty =
                (from PropertyDescriptor property in TypeDescriptor.GetProperties(bindingContext.ModelType)
                 where property.Name == ID_PROPERTY_NAME
                 select property).SingleOrDefault();

            if (idProperty != null && !modelProperties.Contains(idProperty))
            {
                modelProperties.Add(idProperty);
            }
        }
Example #8
0
        public static void CopyProperty(object obj, object toObj)
        {
            PropertyDescriptorCollection objPropertites   = TypeDescriptor.GetProperties(obj);
            PropertyDescriptorCollection toObjPropertites = TypeDescriptor.GetProperties(toObj);

            foreach (PropertyDescriptor item in objPropertites)
            {
                if (toObjPropertites.Contains(item))
                {
                    toObjPropertites[item.Name].SetValue(toObj, item.GetValue(obj));
                }
            }
        }
Example #9
0
        protected virtual Object GetPropertyValueInternal(PropertyDescriptor property)
        {
            PropertyDescriptorCollection classProperties = GetClassProperties();

            if (classProperties.Contains(property))
            {
                String propertyName = property.Name;

                GetObjectProperty(propertyName);
            }

            if (_instanceProperties.Contains(property))
            {
                Object value;

                return(_propertyValues != null && _propertyValues.TryGetValue(property, out value)
                           ? value
                           : null);
            }

            throw new InvalidOperationException("Property doesn't exist in this instance: " +
                                                property.Name);
        }
Example #10
0
        public object GetPropertyOwner(System.ComponentModel.PropertyDescriptor pd)
        {
            if (pd == null)
            {
                return(this);
            }

            if (thisProperties.Contains(pd))
            {
                return(this);
            }

            return(targetControl);
        }
Example #11
0
        public static CustomPropertyCollection PreFilterCustomPropertyCollection(object o, Type typeToIgnore)
        {
            CustomPropertyCollection     collection      = new CustomPropertyCollection();
            PropertyDescriptorCollection thisdescriptors = TypeDescriptor.GetProperties(o.GetType());
            PropertyDescriptorCollection descriptors     = TypeDescriptor.GetProperties(typeToIgnore);

            foreach (PropertyDescriptor pd in thisdescriptors)
            {
                if (descriptors.Contains(pd))
                {
                    continue;
                }
                CustomProperty cp = GetCustomProperty(o, pd.Name);
                if (cp != null)
                {
                    collection.Add(cp);
                }
            }
            return(collection);
        }
        public void RemoveExistingTests(int index)
        {
            var propertyDescriptors = new PropertyDescriptor[]
            {
                new MockPropertyDescriptor("propertyDescriptor1"),
                new MockPropertyDescriptor("propertyDescriptor2"),
                new MockPropertyDescriptor("propertyDescriptor3"),
                new MockPropertyDescriptor("propertyDescriptor4"),
                new MockPropertyDescriptor("propertyDescriptor5"),
                new MockPropertyDescriptor("propertyDescriptor6"),
                new MockPropertyDescriptor("propertyDescriptor7"),
                new MockPropertyDescriptor("propertyDescriptor8"),
                new MockPropertyDescriptor("propertyDescriptor9")
            };

            // Must send in a copy to the constructor as the array itself is manipulated
            var collection = new PropertyDescriptorCollection(propertyDescriptors.ToArray());

            Assert.True(index >= 0 && index < propertyDescriptors.Length, $"Index '{index}' is out of bounds");

            collection.Remove(propertyDescriptors[index]);

            for (int i = 0; i < propertyDescriptors.Length; i++)
            {
                if (i == index)
                {
                    Assert.False(collection.Contains(propertyDescriptors[index]), "Should have removed descriptor");
                }
                else
                {
                    Assert.True(collection.Contains(propertyDescriptors[i]), $"Descriptor should be in collection: {i}");
                }
            }
        }
Example #13
0
        public void SetCurrentObject(IEnumerable <object> obj, bool isEnable = true, bool isRootNode = false, string rootType = "")
        {
            this.isRootNode    = isRootNode;
            this.currentObject = (object)obj;
            if (this._property != null)
            {
                foreach (PropertyItem propertyItem in this._property)
                {
                    if (propertyItem != null && propertyItem.TypeEditor != null)
                    {
                        propertyItem.TypeEditor.EditorDispose();
                    }
                }
            }
            foreach (Widget child in this.container.Children)
            {
                this.container.Remove(child);
            }
            foreach (Widget child in this._propertyTable.Children)
            {
                this._propertyTable.Remove(child);
            }
            if (this._property == null)
            {
                this._property = new List <PropertyItem>();
            }
            this._property.Clear();
            if (obj == null)
            {
                return;
            }
            List <object> source = new List <object>();

            foreach (object obj1 in obj)
            {
                object item = obj1;
                if (source.FirstOrDefault <object>((Func <object, bool>)(w => w.GetType().Name == item.GetType().Name)) == null)
                {
                    source.Add(item);
                }
            }
            if (source.Count <object>() == 0)
            {
                return;
            }
            PropertyDescriptorCollection propertyDescriptors1   = PropertyGridUtilities.GetPropertyDescriptors(this.currentObject = source[0]);
            List <PropertyDescriptor>    propertyDescriptorList = new List <PropertyDescriptor>();

            foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors1)
            {
                propertyDescriptorList.Add(propertyDescriptor);
            }
            for (int index1 = 1; index1 <= source.Count - 1; ++index1)
            {
                PropertyDescriptorCollection propertyDescriptors2 = PropertyGridUtilities.GetPropertyDescriptors(source[index1]);
                for (int index2 = propertyDescriptorList.Count - 1; index2 >= 0; --index2)
                {
                    PropertyDescriptor propertyDescriptor1 = propertyDescriptorList[index2];
                    if (!propertyDescriptors2.Contains(propertyDescriptor1))
                    {
                        propertyDescriptorList.RemoveAt(index2);
                    }
                    else
                    {
                        PropertyDescriptor propertyDescriptor2 = propertyDescriptors2.Find(propertyDescriptor1.Name, true);
                        if (propertyDescriptor2 != null && (propertyDescriptor2.Attributes.OfType <BrowsableAttribute>().FirstOrDefault <BrowsableAttribute>() == null || !propertyDescriptor2.Attributes.OfType <BrowsableAttribute>().FirstOrDefault <BrowsableAttribute>().Browsable))
                        {
                            propertyDescriptorList.RemoveAt(index2);
                        }
                    }
                }
            }
            ITransform currentObject = this.currentObject as ITransform;

            foreach (PropertyDescriptor property in propertyDescriptorList)
            {
                if (property.Attributes.Contains((Attribute) new UndoPropertyAttribute()) || !string.IsNullOrEmpty(property.Category))
                {
                    PropertyItem propertyItem = PropertyGridUtilities.CreatePropertyItem(property, obj.LastOrDefault <object>());
                    if (propertyItem != null)
                    {
                        propertyItem.IsEnable      = isEnable;
                        propertyItem.InstanceList  = obj.ToList <object>();
                        propertyItem.InstanceCount = obj.Count <object>();
                        if (obj.Count <object>() <= 1 || !(propertyItem.Calegory != "Group_Routine"))
                        {
                            this._property.Add(propertyItem);
                        }
                    }
                }
            }
            int type = this._selectTab;

            if (this.currentObject is IPropertyTitle)
            {
                this._generalGrid = new GeneralGrid(new List <string>()
                {
                    LanguageInfo.BasicProperty,
                    LanguageInfo.AdvancedProperty
                }, 0, this._selectTab);
                this._generalGrid.TabChanged += new EventHandler <TabEventArgs>(this._generalGrid_TabChanged);
                this._propertyTable.Attach((Widget)this._generalGrid, 0U, 1U, 0U, 1U, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 1U, 0U);
                this._generalGrid.Show();
                this._titleTable = new GeneralTitle(this._editorManager);
                this._propertyTable.Attach((Widget)this._titleTable.hBox, 0U, 1U, 1U, 2U, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 1U, 0U);
                this._titleTable.hBox.Show();
                if (this.currentObject is IPropertyTitle)
                {
                    this._titleTable.SetImage(obj.Count <object>() == 1 ? this.currentObject : (object)null, obj.Count <object>(), rootType);
                }
                List <PropertyItem> list = this._property.Where <PropertyItem>((Func <PropertyItem, bool>)(w => w.DiaplayName == "Display_Name" || w.DiaplayName == "Display_Target")).ToList <PropertyItem>();
                if (list != null)
                {
                    this._titleTable.SetControl(list);
                }
                if (list != null)
                {
                    list.ForEach((System.Action <PropertyItem>)(w => this._property.Remove(w)));
                }
                PropertyItem propertyItem = this._property.FirstOrDefault <PropertyItem>((Func <PropertyItem, bool>)(w => w.DiaplayName == "CallBack_ClassName"));
                if (propertyItem != null)
                {
                    if (isRootNode)
                    {
                        this._property.Clear();
                        this._property.Add(propertyItem);
                    }
                    else
                    {
                        this._property.Remove(propertyItem);
                    }
                }
            }
            else
            {
                type = 0;
            }
            this.AddTable(type);
        }