/// <summary>
        /// 这里如果使用完全限定类型名的编辑器,则编辑器类不能跨越UnvaryingSagacity.Core.Dll
        /// 一定要使用时,需要在自身的程序集中继承类:CustomAttribute,UniqueChecker,ItemStylePropertyDescription
        /// 请参考UnvaryingSagacity.SuitSchemePrinter.DynamicPropertyDescriptor.cs
        /// </summary>
        /// <param name="item"></param>
        /// <param name="attributes"></param>
        public ItemStylePropertyDescription(CustomAttribute item, Attribute[] attributes)
            : base(item.Name, attributes)
        {
            _itemStyle = item;
            int i = base.AttributeArray.Length;

            _attribute = new Attribute[base.AttributeArray.Length + 6];
            base.AttributeArray.CopyTo(_attribute, 0);
            //Array.Resize<Attribute>(ref _attribute, i + 1);
            _attribute[i] = new PropertyOrderAttribute(_itemStyle.Order);
            i++;
            //Array.Resize<Attribute>(ref _attribute, i + 1);
            _attribute[i] = new PropertyUniqueAttribute(_itemStyle.Checker != null ? true : false, _itemStyle.Checker != null ? _itemStyle.Checker.MethodName : "");
            i++;
            _attribute[i] = new PropertyValidAttribute(_itemStyle.ValidChecker != null ? true : false, _itemStyle.ValidChecker != null ? _itemStyle.ValidChecker.MethodName : "");
            i++;
            _attribute[i] = new PropertyValueCheckerAttribute(_itemStyle.ValueChecker != null ? true : false, _itemStyle.ValueChecker != null ? _itemStyle.ValueChecker.MethodName : "");
            i++;
            //Array.Resize<Attribute>(ref _attribute, i + 1);
            _attribute[i] = new EditorAttribute(_itemStyle.EditorTypeName, typeof(System.Drawing.Design.UITypeEditor));
            i++;
            //Array.Resize<Attribute>(ref _attribute, i + 1);
            _attribute[i]        = new ReadOnlyAttribute(_itemStyle.ReadOnly);
            _attributeCollection = new AttributeCollection(_attribute);
        }
示例#2
0
        private PropertyDescriptor[] OrderPropertyDescriptors(IEnumerable <PropertyDescriptor> propertyDescriptorsToReturn)
        {
            var unorderedProperties    = new List <PropertyDescriptor>();
            var propertiesWithOrdering = new List <Tuple <int, PropertyDescriptor> >();

            foreach (PropertyDescriptor pd in propertyDescriptorsToReturn)
            {
                PropertyOrderAttribute propertyOrderAttribute = pd.Attributes.OfType <PropertyOrderAttribute>().FirstOrDefault();
                if (propertyOrderAttribute != null)
                {
                    propertiesWithOrdering.Add(Tuple.Create(propertyOrderAttribute.Order, pd));
                    continue;
                }

                DynamicPropertyOrderAttribute dynamicPropertyOrderAttribute = pd.Attributes.OfType <DynamicPropertyOrderAttribute>().FirstOrDefault();
                if (dynamicPropertyOrderAttribute != null)
                {
                    propertiesWithOrdering.Add(Tuple.Create(DynamicPropertyOrderAttribute.PropertyOrder(WrappedObject, pd.Name), pd));
                    continue;
                }

                unorderedProperties.Add(pd);
            }

            IEnumerable <PropertyDescriptor> orderedProperties = propertiesWithOrdering.OrderBy(p => p.Item1).Select(p => p.Item2);

            return(orderedProperties.Concat(unorderedProperties).ToArray());
        }
示例#3
0
        /// <summary>
        /// Возвращает упорядоченный список свойств.
        /// </summary>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(value, attributes);
            ArrayList orderedProperties      = new ArrayList();

            foreach (PropertyDescriptor pd in pdc)
            {
                Attribute attribute = pd.Attributes[typeof(PropertyOrderAttribute)];

                if (attribute != null)
                {
                    // атрибут есть - используем номер п/п из него
                    PropertyOrderAttribute poa = (PropertyOrderAttribute)attribute;
                    orderedProperties.Add(new PropertyOrderPair(pd.Name, poa.Order));
                }
                else
                {
                    // атрибута нет – считаем, что 0
                    orderedProperties.Add(new PropertyOrderPair(pd.Name, 0));
                }
            }

            // сортируем по Order-у
            orderedProperties.Sort();

            // формируем список имен свойств
            ArrayList propertyNames = new ArrayList();

            foreach (PropertyOrderPair pop in orderedProperties)
            {
                propertyNames.Add(pop.Name);
            }

            return(pdc.Sort((string[])propertyNames.ToArray(typeof(string))));
        }
示例#4
0
        public void PropertyOrderAttributeConstructorTest()
        {
            int order = 0; // TODO: Initialize to an appropriate value
            PropertyOrderAttribute target = new PropertyOrderAttribute(order);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
示例#5
0
        public void OrderTest()
        {
            int order = 0;                                                     // TODO: Initialize to an appropriate value
            PropertyOrderAttribute target = new PropertyOrderAttribute(order); // TODO: Initialize to an appropriate value
            int actual;

            actual = target.Order;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
示例#6
0
 private void ValidatePropertyOrderAttributes(List <PropertyOrderAttribute> list)
 {
     if (list.Count > 0)
     {
         PropertyOrderAttribute both = list.FirstOrDefault(x => x.UsageContext == UsageContextEnum.Both);
         if ((both != null) && (list.Count > 1))
         {
             Debug.Assert(false, "A PropertyItem can't have more than 1 PropertyOrderAttribute when it has UsageContext : Both");
         }
     }
 }
示例#7
0
        public void ParameteredConstructor_ExpectedValues()
        {
            // Setup
            int order = new Random(21).Next(int.MinValue, int.MaxValue);

            // Call
            var attribute = new PropertyOrderAttribute(order);

            // Assert
            Assert.IsInstanceOf <Attribute>(attribute);
            Assert.AreEqual(order, attribute.Order);
        }
        // <summary>
        // Gets the PropertyOrder token associated with the given ModelProperty
        // </summary>
        // <param name="property">ModelProperty to examine</param>
        // <returns>Associated PropertyOrder token if one exists, null otherwise.</returns>
        public static PropertyOrder GetPropertyOrder(ModelProperty property)
        {
            if (property == null)
            {
                return(null);
            }

            PropertyOrderAttribute attr = GetAttribute <PropertyOrderAttribute>(property);

            if (attr == null)
            {
                return(null);
            }

            return(attr.Order);
        }
示例#9
0
    public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
    {
        //
        // This override returns a list of properties in order
        //
        PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(value, attributes);
        ArrayList orderedProperties      = new ArrayList();

        foreach (PropertyDescriptor pd in pdc)
        {
            Attribute attribute = pd.Attributes[typeof(PropertyOrderAttribute)];
            if (attribute != null)
            {
                //
                // If the attribute is found, then create an pair object to hold it
                //
                PropertyOrderAttribute poa = (PropertyOrderAttribute)attribute;
                orderedProperties.Add(new PropertyOrderPair(pd.Name, poa.Order));
            }
            else
            {
                //
                // If no order attribute is specifed then given it an order of 0
                //
                orderedProperties.Add(new PropertyOrderPair(pd.Name, 0));
            }
        }
        //
        // Perform the actual order using the value PropertyOrderPair classes
        // implementation of IComparable to sort
        //
        orderedProperties.Sort();
        //
        // Build a string list of the ordered names
        //
        ArrayList propertyNames = new ArrayList();

        foreach (PropertyOrderPair pop in orderedProperties)
        {
            propertyNames.Add(pop.Name);
        }
        //
        // Pass in the ordered list for the PropertyDescriptorCollection to sort by
        //
        return(pdc.Sort((string[])propertyNames.ToArray(typeof(string))));
    }
示例#10
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            ArrayList orderedProperties            = new ArrayList();
            PropertyDescriptorCollection retProps  = new PropertyDescriptorCollection(null);
            PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties(obj, attributes, true);

            foreach (PropertyDescriptor oProp in baseProps)
            {
                Attribute attOrder = oProp.Attributes[typeof(PropertyOrderAttribute)];
                if (false == IsPropertyVisible(oProp))
                {
                    continue;
                }

                if (attOrder != null)
                {
                    //
                    // If the attribute is found, then create an pair object to hold it
                    //
                    PropertyOrderAttribute poa = (PropertyOrderAttribute)attOrder;
                    orderedProperties.Add(new PropertyOrderPair(oProp, oProp.Name, poa.Order));
                }
                else
                {
                    //
                    // If no order attribute is specifed then given it an order of 0
                    //
                    orderedProperties.Add(new PropertyOrderPair(oProp, oProp.Name, 0));
                }
                //retProps.Add (new GlobalizedPropertyDescriptor(oProp));

                //Console.WriteLine ("Enumerating property {0}", oProp.DisplayName);
                //PGDisplayName invisible = (PGDisplayName)oProp.Attributes[typeof(PGNotVisible)];
                //if (invisible == null)
                //else
                //	Console.WriteLine ("Property {0} is invisible", oProp.DisplayName);
            }

            orderedProperties.Sort();
            foreach (PropertyOrderPair pop in orderedProperties)
            {
                Console.WriteLine("Adding sorted {0}", pop.Name);
                retProps.Add(new GlobalizedPropertyDescriptor(pop.Property));
            }
            return(retProps);
        }
        private static PropertyDescriptorCollection SortProperties(PropertyDescriptorCollection pdc)
        {
            List <PropertyOrderPair> orderedProperties = new List <PropertyOrderPair>();

            foreach (PropertyDescriptor pd in pdc)
            {
                Attribute attribute = pd.Attributes[typeof(PropertyOrderAttribute)];
                if (attribute != null)
                {
                    //
                    // If the attribute is found, then create an pair object to hold it
                    //
                    PropertyOrderAttribute poa = (PropertyOrderAttribute)attribute;
                    orderedProperties.Add(new PropertyOrderPair(pd.Name, poa.Order));
                }
                else
                {
                    //
                    // If no order attribute is specifed then given it an order of 0
                    //
                    orderedProperties.Add(new PropertyOrderPair(pd.Name, 0));
                }
            }
            //
            // Perform the actual order using the value PropertyOrderPair classes
            // implementation of IComparable to sort
            //
            orderedProperties.Sort();
            //
            // Build a string list of the ordered names
            //
            List <string> propertyNames = new List <string>();

            foreach (PropertyOrderPair pop in orderedProperties)
            {
                propertyNames.Add(pop.Name);
            }
            //
            // Pass in the ordered list for the PropertyDescriptorCollection to sort by
            //
            return(pdc.Sort(propertyNames.ToArray()));
        }
示例#12
0
    public int Compare(object x, object y)
    {
        if (x == y)
        {
            return(0);
        }
        if (x == null)
        {
            return(1);
        }
        if (y == null)
        {
            return(-1);
        }

        PropertyDescriptor propertyDescriptorX = x as PropertyDescriptor;
        PropertyDescriptor propertyDescriptorY = y as PropertyDescriptor;

        PropertyOrderAttribute propertyOrderAttributeX = propertyDescriptorX.Attributes[typeof(PropertyOrderAttribute)] as PropertyOrderAttribute;
        PropertyOrderAttribute propertyOrderAttributeY = propertyDescriptorY.Attributes[typeof(PropertyOrderAttribute)] as PropertyOrderAttribute;

        if (propertyOrderAttributeX == propertyOrderAttributeY)
        {
            return(0);
        }
        if (propertyOrderAttributeX == null)
        {
            return(1);
        }
        if (propertyOrderAttributeY == null)
        {
            return(-1);
        }

        return(propertyOrderAttributeX.Order.CompareTo(propertyOrderAttributeY.Order));
    }
示例#13
0
        public void ShouldAssignOrder()
        {
            PropertyOrderAttribute attribute = new PropertyOrderAttribute(10);

            Assert.AreEqual <int>(10, attribute.Order);
        }
示例#14
0
        /// <summary>
        /// Наполнить колонки на основе типа.
        /// </summary>
        /// <param name="columns">Коллекция колонок</param>
        /// <param name="type">Тип, размеченный аттрибутами</param>
        public static void ParseAllPropsIntoColumns(DataGridViewColumnCollection columns, Type type)
        {
            PropertyInfo[] props      = type.GetProperties();
            ArrayList      propsNames = new ArrayList(props.Length);

            foreach (PropertyInfo prop in props)
            {
                PropertyOrderAttribute att = (PropertyOrderAttribute)Attribute.GetCustomAttribute(prop, typeof(PropertyOrderAttribute));
                if (att != null)
                {
                    propsNames.Add(new PropertyOrderPair(prop.Name, att.Order));
                }
                else
                {
                    propsNames.Add(new PropertyOrderPair(prop.Name, 0));
                }
            }

            propsNames.Sort();

            DataGridViewCell cell = new DataGridViewTextBoxCell();

            for (int i = 0; i < propsNames.Count; ++i)
            {
                PropertyInfo prop = type.GetProperty((propsNames[i] as PropertyOrderPair).Name);

                ColumnNameAttribute attName = (ColumnNameAttribute)Attribute.GetCustomAttribute(prop, typeof(ColumnNameAttribute));
                if (attName != null)
                {
                    DataGridViewColumn column = new DataGridViewColumn();
                    column.Name         = attName.ColumnName;
                    column.CellTemplate = cell;

                    ColumnWidthAttribute attWidth = (ColumnWidthAttribute)Attribute.GetCustomAttribute(prop, typeof(ColumnWidthAttribute));
                    if (attWidth != null)
                    {
                        column.Width = attWidth.ColumnWidth;
                    }
                    else
                    {
                        column.Width = 100;
                    }

                    ColumnTextAttribute attText = (ColumnTextAttribute)Attribute.GetCustomAttribute(prop, typeof(ColumnTextAttribute));
                    if (attText != null)
                    {
                        column.HeaderText = attText.ColumnText;
                    }
                    else
                    {
                        column.HeaderText = attName.ColumnName;
                    }

                    if (prop.GetSetMethod() != null)
                    {
                        ReadOnlyAttribute attRO = (ReadOnlyAttribute)Attribute.GetCustomAttribute(prop, typeof(ReadOnlyAttribute));
                        if (attRO != null)
                        {
                            column.ReadOnly = attRO.IsReadOnly;
                        }
                    }

                    ContentAlignmentAttribute attAl = (ContentAlignmentAttribute)Attribute.GetCustomAttribute(prop, typeof(ContentAlignmentAttribute));
                    if (attAl != null)
                    {
                        column.HeaderCell.Style.Alignment = (DataGridViewContentAlignment)(attAl.Alignment);
                    }

                    columns.Add(column);
                }
            }
        }