コード例 #1
0
        private void BuildNormalCollection(object instance, bool noCategory, bool automaticlyExpandObjects, List <Property> propertyCollection, string filter, bool readOnly)
        {
            Dictionary <string, PropertyCategory> groups = new Dictionary <string, PropertyCategory>();
            PropertyDescriptorCollection          properties;

            if (instance != null)
            {
                properties = TypeDescriptor.GetProperties(instance);                  //I changed here from instance to instance.GetType, so that only the Direct Properties are shown!
            }
            else
            {
                properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { });
            }

            foreach (PropertyDescriptor propertyDescriptor in properties)
            {
                CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter, readOnly);
                if (noCategory)
                {
                    propertyCollection.Sort(Property.CompareByName);
                }
                else
                {
                    propertyCollection.Sort(Property.CompareByCategoryThenByName);
                }
            }

            if (noCategory)
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        Items.Add(property);
                    }
                }
            }
            else
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        PropertyCategory propertyCategory;
                        if (groups.ContainsKey(property.Category))
                        {
                            propertyCategory = groups[property.Category];
                        }
                        else
                        {
                            propertyCategory          = new PropertyCategory(property.Category);
                            groups[property.Category] = propertyCategory;
                            Items.Add(propertyCategory);
                        }
                        propertyCategory.Items.Add(property);
                    }
                }
            }
        }
コード例 #2
0
        //public PropertyCollection(object instance)
        //    : this(instance, false)
        //{ }
        public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter)
        {
            Dictionary<string, PropertyCategory> groups = new Dictionary<string, PropertyCategory>();
            PropertyDescriptorCollection properties ;
            if (instance != null)
                properties = TypeDescriptor.GetProperties(instance.GetType());  //I changed here from instance to instance.GetType, so that only the Direct Properties are shown!
            else
                properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { });

            List<Property> propertyCollection = new List<Property>();

            foreach (PropertyDescriptor propertyDescriptor in properties)
            {
                CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter);
                if (noCategory)
                    propertyCollection.Sort(Property.CompareByName);
                else
                    propertyCollection.Sort(Property.CompareByCategoryThenByName);
            }

            if (noCategory)
            {

                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                        Items.Add(property);
                }
            }
            else
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        PropertyCategory propertyCategory;
                        if (groups.ContainsKey(property.Category))
                        {
                            propertyCategory = groups[property.Category];
                        }
                        else
                        {
                            propertyCategory = new PropertyCategory(property.Category);
                            groups[property.Category] = propertyCategory;
                            Items.Add(propertyCategory);
                        }
                        propertyCategory.Items.Add(property);
                    }
                }
            }
        }
コード例 #3
0
        public PropertyCollection(object instance, bool noCategory, bool alphabetical, bool automaticlyExpandObjects, string filter, Property parentProperty, bool parentIsValueType, PropertyGrid hostGrid, bool mergeMultiValue = false)
        {
            //bool useCustomTypeConverter = false;
            List <EditorCommon.CustomPropertyDescriptorCollection> propertyCollections = new List <EditorCommon.CustomPropertyDescriptorCollection>();
            List <EditorCommon.CustomPropertyDescriptorCollection> fieldCollections    = new List <EditorCommon.CustomPropertyDescriptorCollection>();

            EditorCommon.CustomPropertyDescriptorCollection properties = null;
            EditorCommon.CustomPropertyDescriptorCollection fields     = null;
            System.Reflection.BindingFlags getFieldsFlag = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic;
            if (instance != null)
            {
                var enumrableInterface = instance.GetType().GetInterface(typeof(IEnumerable).FullName, false);
                if (enumrableInterface != null)
                {
                    // 显示多个对象
                    foreach (var objIns in (IEnumerable)instance)
                    {
                        if (objIns == null)
                        {
                            continue;
                        }
                        var objType = objIns.GetType();
                        EditorCommon.CustomPropertyDescriptorCollection tempProperties;
                        if (!mPropertyDesColDic.TryGetValue(objType, out tempProperties))
                        {
                            PropertyDescriptorCollection pros;
                            var tc = TypeDescriptor.GetConverter(objIns);
                            if (tc == null || !tc.GetPropertiesSupported())
                            {
                                if (objIns is ICustomTypeDescriptor)
                                {
                                    pros = ((ICustomTypeDescriptor)instance).GetProperties();
                                }
                                else
                                {
                                    pros = TypeDescriptor.GetProperties(objIns);
                                }
                            }
                            else
                            {
                                pros = tc.GetProperties(objIns);
                            }
                            tempProperties = new EditorCommon.CustomPropertyDescriptorCollection(objType, pros, parentIsValueType);
                            mPropertyDesColDic[objType] = tempProperties;
                            if (objType.Name == "CGfxMeshImportOption")
                            {
                                int s = 0;
                                s = 1;
                            }
                        }
                        if (objType.Name == "CGfxMeshImportOption")
                        {
                            int s = 0;
                            s = 1;
                        }
                        if (mergeMultiValue)
                        {
                            if (properties == null)
                            {
                                var pros = new EditorCommon.CustomPropertyDescriptor[tempProperties.Count];
                                tempProperties.CopyTo(pros, 0);
                                properties = new EditorCommon.CustomPropertyDescriptorCollection(pros);
                                //properties = tempProperties;
                            }
                            else if (properties.Properties == tempProperties.Properties)
                            {
                                for (int i = properties.Count - 1; i >= 0; i--)
                                {
                                    var idx = tempProperties.IndexOf(properties[i]);
                                    if (idx >= 0)
                                    {
                                        var item = tempProperties[idx];
                                        properties[i].Add(item);
                                    }
                                    else
                                    {
                                        properties.RemoveAt(i);
                                    }
                                }
                            }
                        }
                        else
                        {
                            propertyCollections.Add(tempProperties);
                        }


                        EditorCommon.CustomPropertyDescriptorCollection tempFields;
                        if (!mFieldInfosDic.TryGetValue(objType, out tempFields))
                        {
                            var fls = objType.GetFields(getFieldsFlag);
                            tempFields = new EditorCommon.CustomPropertyDescriptorCollection(objType, fls, parentIsValueType);
                            mFieldInfosDic[objType] = tempFields;
                        }
                        if (mergeMultiValue)
                        {
                            if (fields == null)
                            {
                                fields = tempFields;
                            }
                            else
                            {
                                for (int i = fields.Count - 1; i >= 0; i--)
                                {
                                    var idx = tempFields.IndexOf(fields[i]);
                                    if (idx >= 0)
                                    {
                                        var item = tempFields[idx];
                                        fields[i].Add(item);
                                    }
                                    else
                                    {
                                        fields.RemoveAt(i);
                                    }
                                }
                            }
                        }
                        else
                        {
                            fieldCollections.Add(tempFields);
                        }
                    }
                }
                else
                {
                    // 显示单个对象
                    var insType = instance.GetType();
                    if (!mPropertyDesColDic.TryGetValue(insType, out properties))
                    {
                        PropertyDescriptorCollection pros;
                        TypeConverter tc = TypeDescriptor.GetConverter(instance);
                        if (tc == null || !tc.GetPropertiesSupported())
                        {
                            if (instance is ICustomTypeDescriptor)
                            {
                                pros = ((ICustomTypeDescriptor)instance).GetProperties();
                            }
                            else
                            {
                                pros = TypeDescriptor.GetProperties(insType);  //I changed here from instance to instance.GetType, so that only the Direct Properties are shown!
                            }
                        }
                        else
                        {
                            pros = tc.GetProperties(instance);
                            //useCustomTypeConverter = true;
                        }
                        properties = new EditorCommon.CustomPropertyDescriptorCollection(insType, pros, parentIsValueType);
                        mPropertyDesColDic[insType] = properties;
                        if (insType.Name == "CGfxMeshImportOption")
                        {
                            int s = 0;
                            s = 1;
                        }
                    }

                    if (!mFieldInfosDic.TryGetValue(insType, out fields))
                    {
                        var flds = insType.GetFields(getFieldsFlag);
                        fields = new EditorCommon.CustomPropertyDescriptorCollection(insType, flds, parentIsValueType);
                        mFieldInfosDic[insType] = fields;
                    }
                }
            }

            if (properties == null)
            {
                properties = new EditorCommon.CustomPropertyDescriptorCollection(new EditorCommon.CustomPropertyDescriptor[] { });
            }
            if (fields == null)
            {
                fields = new EditorCommon.CustomPropertyDescriptorCollection(new EditorCommon.CustomPropertyDescriptor[] { });
            }

            if (mergeMultiValue || instance == null)
            {
                List <Property> propertyCollection           = new List <Property>();
                Dictionary <string, PropertyCategory> groups = new Dictionary <string, PropertyCategory>();
                foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in properties)
                {
                    CollectProperties(instance, propertyDescriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, mergeMultiValue);
                }
                foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in fields)
                {
                    CollectProperties(instance, propertyDescriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, mergeMultiValue);
                }

                ProcessPropertyCollection(parentProperty, propertyCollection, noCategory, alphabetical, filter, groups, Items);
            }
            else
            {
                var enumrableInterface = instance.GetType().GetInterface(typeof(IEnumerable).FullName, false);
                if (enumrableInterface != null)
                {
                    int idxShow = 1;  // 从1开始算
                    foreach (var objIns in (IEnumerable)instance)
                    {
                        Dictionary <string, PropertyCategory> groups = new Dictionary <string, PropertyCategory>();
                        List <Property> tempProCollection            = new List <Property>();
                        if (propertyCollections.Count >= idxShow)
                        {
                            var pros = propertyCollections[idxShow - 1];
                            foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in pros)
                            {
                                CollectProperties(objIns, propertyDescriptor, tempProCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, mergeMultiValue);
                            }
                            var field = fieldCollections[idxShow - 1];
                            foreach (EditorCommon.CustomPropertyDescriptor fieldDescriptor in field)
                            {
                                CollectProperties(objIns, fieldDescriptor, tempProCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, mergeMultiValue);
                            }
                            var atts       = objIns.GetType().GetCustomAttributes(typeof(EngineNS.Editor.Editor_DisplayNameInEnumerable), true);
                            var nameString = idxShow.ToString();
                            if (atts.Length > 0)
                            {
                                var att = atts[0] as EngineNS.Editor.Editor_DisplayNameInEnumerable;
                                nameString += " " + att.DisplayName;
                            }
                            var category = new PropertyCategory(nameString);
                            ProcessPropertyCollection(parentProperty, tempProCollection, noCategory, alphabetical, filter, groups, category.Items);
                            Items.Add(category);
                            idxShow++;
                        }
                    }
                }
                else
                {
                    List <Property> propertyCollection           = new List <Property>();
                    Dictionary <string, PropertyCategory> groups = new Dictionary <string, PropertyCategory>();
                    foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in properties)
                    {
                        CollectProperties(instance, propertyDescriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, mergeMultiValue);
                    }
                    foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in fields)
                    {
                        CollectProperties(instance, propertyDescriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, mergeMultiValue);
                    }

                    ProcessPropertyCollection(parentProperty, propertyCollection, noCategory, alphabetical, filter, groups, Items);
                }
            }
        }
コード例 #4
0
        void ProcessPropertyCollection(Property parentProperty, List <Property> propertyCollection, bool noCategory, bool alphabetical, string filter, Dictionary <string, PropertyCategory> groups, ObservableCollection <Item> items)
        {
            EditorCommon.Editor_PropertyGridSortTypeAttribute sortAtt = null;
            if (parentProperty != null)
            {
                foreach (var valueAtt in parentProperty.ValueAttributes)
                {
                    var att = valueAtt as EditorCommon.Editor_PropertyGridSortTypeAttribute;
                    if (att != null)
                    {
                        sortAtt = att;
                        break;
                    }
                }
            }

            // 筛选GPlacementComponent
            var             placementCompType = typeof(EngineNS.GamePlay.Component.GPlacementComponent);
            List <Property> placementPros     = new List <Property>();

            for (int i = propertyCollection.Count - 1; i >= 0; i--)
            {
                var pro = propertyCollection[i];
                if (pro.PropertyType == placementCompType ||
                    pro.PropertyType.IsSubclassOf(placementCompType))
                {
                    placementPros.Add(pro);
                    propertyCollection.RemoveAt(i);
                }
            }

            if (noCategory)
            {
                if (sortAtt != null)
                {
                    switch (sortAtt.SortType)
                    {
                    case EditorCommon.Editor_PropertyGridSortTypeAttribute.enSortType.NoSort:
                        break;

                    case EditorCommon.Editor_PropertyGridSortTypeAttribute.enSortType.Custom:
                        propertyCollection.Sort(sortAtt.Comparer);
                        break;
                    }
                }
                else
                {
                    if (alphabetical)
                    {
                        propertyCollection.Sort(Property.CompareByName);
                    }
                    else
                    {
                        propertyCollection.Sort(Property.CompareBySortIndex);
                    }
                }

                foreach (var pro in placementPros)
                {
                    if (filter == "" || pro.Name.ToLower().Contains(filter))
                    {
                        items.Add(pro);
                    }
                }
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        items.Add(property);
                    }
                }
            }
            else
            {
                if (sortAtt != null)
                {
                    switch (sortAtt.SortType)
                    {
                    case EditorCommon.Editor_PropertyGridSortTypeAttribute.enSortType.NoSort:
                        break;

                    case EditorCommon.Editor_PropertyGridSortTypeAttribute.enSortType.Custom:
                        propertyCollection.Sort(sortAtt.Comparer);
                        break;
                    }
                }
                else
                {
                    if (alphabetical)
                    {
                        propertyCollection.Sort(Property.CompareByCategoryThenByName);
                    }
                    else
                    {
                        propertyCollection.Sort(Property.CompareBySortIndex);
                    }
                }

                foreach (var pro in placementPros)
                {
                    if (filter == "" || pro.Name.ToLower().Contains(filter))
                    {
                        items.Add(pro);
                    }
                }
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        PropertyCategory propertyCategory = null;
                        var category = property.Category ?? string.Empty; // null category handled here

                        if (groups.ContainsKey(category))
                        {
                            propertyCategory = groups[category];
                        }
                        else
                        {
                            var noCa = false;
                            foreach (var att in property.PGProperty.Attributes)
                            {
                                if (att is EngineNS.Editor.Editor_NoCategoryAttribute)
                                {
                                    noCa = true;
                                    break;
                                }
                            }
                            if (noCa)
                            {
                                items.Add(property);
                            }
                            else
                            {
                                propertyCategory = new PropertyCategory(property.Category);
                                groups[category] = propertyCategory;
                                items.Add(propertyCategory);
                            }
                        }
                        propertyCategory?.Items.Add(property);
                    }
                }
            }
        }
コード例 #5
0
ファイル: PropertyCollection.cs プロジェクト: Jedzia/BackBock
        //public PropertyCollection(object instance)
        //    : this(instance, false)
        //{ }
        public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter)
        {
            Dictionary<string, PropertyCategory> groups = new Dictionary<string, PropertyCategory>();

            bool useCustomTypeConverter = false;

            PropertyDescriptorCollection properties;
            if (instance != null)
            {
                TypeConverter tc = TypeDescriptor.GetConverter(instance);
                if (tc == null || !tc.GetPropertiesSupported())
                {

                    if (instance is ICustomTypeDescriptor)
                        properties = ((ICustomTypeDescriptor)instance).GetProperties();
                    else
                        properties = TypeDescriptor.GetProperties(instance.GetType());  //I changed here from instance to instance.GetType, so that only the Direct Properties are shown!
                }
                else
                {
                    properties = tc.GetProperties(instance);
                    useCustomTypeConverter = true;
                }
            }
            else
                properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { });

            List<Property> propertyCollection = new List<Property>();

            foreach (PropertyDescriptor propertyDescriptor in properties)
            {
                bool skipProperty = false;
                foreach (var item in propertyDescriptor.Attributes)
                {
                    if (item is DesignerSerializationVisibilityAttribute)
                    {
                        if (((DesignerSerializationVisibilityAttribute)item).Visibility == DesignerSerializationVisibility.Hidden)
                        {
                            skipProperty = true;
                            break;
                        }
                    }
                    if (item is EditorBrowsableAttribute)
                    {
                        if (((EditorBrowsableAttribute)item).State == EditorBrowsableState.Never)
                        {
                            skipProperty = true;
                            break;
                        }
                    }
                }
                if (skipProperty)
                {
                    continue;
                }

                if (useCustomTypeConverter)
                {
                    Property property = new Property(instance, propertyDescriptor);
                    propertyCollection.Add(property);
                }
                else
                {
                    CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter);
                    if (noCategory)
                        propertyCollection.Sort(Property.CompareByName);
                    else
                        propertyCollection.Sort(Property.CompareByCategoryThenByName);
                }
            }

            if (noCategory)
            {

                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                        Items.Add(property);
                }
            }
            else
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        PropertyCategory propertyCategory;
                        var category = property.Category ?? string.Empty; // null category handled here

                        if (groups.ContainsKey(category))
                        {
                            propertyCategory = groups[category];
                        }
                        else
                        {
                            propertyCategory = new PropertyCategory(property.Category);
                            groups[category] = propertyCategory;
                            Items.Add(propertyCategory);
                        }
                        propertyCategory.Items.Add(property);
                    }
                }
            }
        }
コード例 #6
0
        public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter)
        {
            Dictionary<string, PropertyCategory> groups = new Dictionary<string, PropertyCategory>();

            bool useCustomTypeConverter = false;

            //PropertyDescriptorCollection properties;
            if (instance != null) {
                TypeConverter tc = TypeDescriptor.GetConverter(instance);
                if (tc == null || !tc.GetPropertiesSupported()) {

                    if (instance is ICustomTypeDescriptor)
                        properties = ((ICustomTypeDescriptor)instance).GetProperties();
                    else
                        properties = TypeDescriptor.GetProperties(instance.GetType());  //I changed here from instance to instance.GetType, so that only the Direct Properties are shown!
                } else {
                    properties = tc.GetProperties(instance);
                    useCustomTypeConverter = true;
                }
            } else
                properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { });

            List<Property> propertyCollection = new List<Property>();

            // new with lang-support
            if (instance.GetType() == typeof(Asterics.ACS.componentType)) {
                componentID = ((Asterics.ACS.componentType)instance).type_id;
            } else if (instance.GetType() == typeof(Asterics.ACS.inputPortType)) {
                componentID = ((Asterics.ACS.inputPortType)instance).ComponentTypeId;
            } else if (instance.GetType() == typeof(Asterics.ACS.outputPortType)) {
                componentID = ((Asterics.ACS.outputPortType)instance).ComponentTypeId;
            }

            foreach (PropertyDescriptor propertyDescriptor in properties) {
                if (useCustomTypeConverter) {
                    Property property = new Property(instance, propertyDescriptor);
                    propertyCollection.Add(property);
                } else {
                    CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter);
                    //if (noCategory)
                    //    propertyCollection.Sort(Property.CompareByName);
                    //else
                    //    propertyCollection.Sort(Property.CompareByCategoryThenByName);
                }
            }

            if (noCategory) {

                foreach (Property property in propertyCollection) {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                        Items.Add(property);
                }
            } else {
                foreach (Property property in propertyCollection) {
                    if (filter == "" || property.Name.ToLower().Contains(filter)) {
                        PropertyCategory propertyCategory;
                        var category = property.Category ?? string.Empty; // null category handled here

                        if (groups.ContainsKey(category)) {
                            propertyCategory = groups[category];
                        } else {
                            propertyCategory = new PropertyCategory(property.Category);
                            groups[category] = propertyCategory;
                            Items.Add(propertyCategory);
                        }
                        propertyCategory.Items.Add(property);
                    }
                }
            }
        }
コード例 #7
0
        //public PropertyCollection(object instance)
        //    : this(instance, false)
        //{ }

        public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter)
        {
            Dictionary <string, PropertyCategory> groups = new Dictionary <string, PropertyCategory>();

            bool useCustomTypeConverter = false;

            PropertyDescriptorCollection properties;

            if (instance != null)
            {
                TypeConverter tc = TypeDescriptor.GetConverter(instance);
                if (tc == null || !tc.GetPropertiesSupported())
                {
                    if (instance is ICustomTypeDescriptor)
                    {
                        properties = ((ICustomTypeDescriptor)instance).GetProperties();
                    }
                    else
                    {
                        properties = TypeDescriptor.GetProperties(instance.GetType());  //I changed here from instance to instance.GetType, so that only the Direct Properties are shown!
                    }
                }
                else
                {
                    properties             = tc.GetProperties(instance);
                    useCustomTypeConverter = true;
                }
            }
            else
            {
                properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { });
            }

            List <Property> propertyCollection = new List <Property>();

            foreach (PropertyDescriptor propertyDescriptor in properties)
            {
                bool skipProperty = false;
                foreach (var item in propertyDescriptor.Attributes)
                {
                    if (item is DesignerSerializationVisibilityAttribute)
                    {
                        if (((DesignerSerializationVisibilityAttribute)item).Visibility == DesignerSerializationVisibility.Hidden)
                        {
                            skipProperty = true;
                            break;
                        }
                    }
                    if (item is EditorBrowsableAttribute)
                    {
                        if (((EditorBrowsableAttribute)item).State == EditorBrowsableState.Never)
                        {
                            skipProperty = true;
                            break;
                        }
                    }
                }
                if (skipProperty)
                {
                    continue;
                }

                if (useCustomTypeConverter)
                {
                    Property property = new Property(instance, propertyDescriptor);
                    propertyCollection.Add(property);
                }
                else
                {
                    CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter);
                    if (noCategory)
                    {
                        propertyCollection.Sort(Property.CompareByName);
                    }
                    else
                    {
                        propertyCollection.Sort(Property.CompareByCategoryThenByName);
                    }
                }
            }

            if (noCategory)
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        Items.Add(property);
                    }
                }
            }
            else
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        PropertyCategory propertyCategory;
                        var category = property.Category ?? string.Empty; // null category handled here

                        if (groups.ContainsKey(category))
                        {
                            propertyCategory = groups[category];
                        }
                        else
                        {
                            propertyCategory = new PropertyCategory(property.Category);
                            groups[category] = propertyCategory;
                            Items.Add(propertyCategory);
                        }
                        propertyCategory.Items.Add(property);
                    }
                }
            }
        }
コード例 #8
0
        public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter)
        {
            Dictionary <string, PropertyCategory> groups = new Dictionary <string, PropertyCategory>();

            bool useCustomTypeConverter = false;

            //PropertyDescriptorCollection properties;
            if (instance != null)
            {
                TypeConverter tc = TypeDescriptor.GetConverter(instance);
                if (tc == null || !tc.GetPropertiesSupported())
                {
                    if (instance is ICustomTypeDescriptor)
                    {
                        properties = ((ICustomTypeDescriptor)instance).GetProperties();
                    }
                    else
                    {
                        properties = TypeDescriptor.GetProperties(instance.GetType());  //I changed here from instance to instance.GetType, so that only the Direct Properties are shown!
                    }
                }
                else
                {
                    properties             = tc.GetProperties(instance);
                    useCustomTypeConverter = true;
                }
            }
            else
            {
                properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { });
            }

            List <Property> propertyCollection = new List <Property>();

            // new with lang-support
            if (instance.GetType() == typeof(Asterics.ACS.componentType))
            {
                componentID = ((Asterics.ACS.componentType)instance).type_id;
            }
            else if (instance.GetType() == typeof(Asterics.ACS.inputPortType))
            {
                componentID = ((Asterics.ACS.inputPortType)instance).ComponentTypeId;
            }
            else if (instance.GetType() == typeof(Asterics.ACS.outputPortType))
            {
                componentID = ((Asterics.ACS.outputPortType)instance).ComponentTypeId;
            }

            foreach (PropertyDescriptor propertyDescriptor in properties)
            {
                if (useCustomTypeConverter)
                {
                    Property property = new Property(instance, propertyDescriptor);
                    propertyCollection.Add(property);
                }
                else
                {
                    CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter);
                    //if (noCategory)
                    //    propertyCollection.Sort(Property.CompareByName);
                    //else
                    //    propertyCollection.Sort(Property.CompareByCategoryThenByName);
                }
            }

            if (noCategory)
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        Items.Add(property);
                    }
                }
            }
            else
            {
                foreach (Property property in propertyCollection)
                {
                    if (filter == "" || property.Name.ToLower().Contains(filter))
                    {
                        PropertyCategory propertyCategory;
                        var category = property.Category ?? string.Empty; // null category handled here

                        if (groups.ContainsKey(category))
                        {
                            propertyCategory = groups[category];
                        }
                        else
                        {
                            propertyCategory = new PropertyCategory(property.Category);
                            groups[category] = propertyCategory;
                            Items.Add(propertyCategory);
                        }
                        propertyCategory.Items.Add(property);
                    }
                }
            }
        }