[Test] // Sort (IComparer) public void Sort3() { PropertyDescriptorCollection descriptors; PropertyDescriptorCollection sorted; PropertyDescriptor descA = new MockPropertyDescriptor("Foo", 2); PropertyDescriptor descB = new MockPropertyDescriptor("Aim", 3); PropertyDescriptor descC = new MockPropertyDescriptor("Bim", 1); PropertyDescriptor descD = new MockPropertyDescriptor("AIm", 5); PropertyDescriptor descE = new MockPropertyDescriptor("Boo", 4); PropertyDescriptor descF = new MockPropertyDescriptor("FOo", 6); PropertyDescriptor [] props = new PropertyDescriptor [] { descA, descB, descC, descD, descE, descF }; descriptors = new PropertyDescriptorCollection(props); Assert.AreSame(descA, descriptors [0], "#A1"); Assert.AreSame(descB, descriptors [1], "#A2"); Assert.AreSame(descC, descriptors [2], "#A3"); Assert.AreSame(descD, descriptors [3], "#A4"); Assert.AreSame(descE, descriptors [4], "#A5"); Assert.AreSame(descF, descriptors [5], "#A6"); sorted = descriptors.Sort(new ComparableComparer()); Assert.AreSame(descA, descriptors [0], "#B1"); Assert.AreSame(descB, descriptors [1], "#B2"); Assert.AreSame(descC, descriptors [2], "#B3"); Assert.AreSame(descD, descriptors [3], "#B4"); Assert.AreSame(descE, descriptors [4], "#B5"); Assert.AreSame(descF, descriptors [5], "#B6"); Assert.AreSame(descC, sorted [0], "#C1"); Assert.AreSame(descA, sorted [1], "#C2"); Assert.AreSame(descB, sorted [2], "#C3"); Assert.AreSame(descE, sorted [3], "#C4"); Assert.AreSame(descD, sorted [4], "#C5"); Assert.AreSame(descF, sorted [5], "#C6"); sorted = descriptors.Sort((Comparer)null); Assert.AreSame(descA, descriptors [0], "#D1"); Assert.AreSame(descB, descriptors [1], "#D2"); Assert.AreSame(descC, descriptors [2], "#D3"); Assert.AreSame(descD, descriptors [3], "#D4"); Assert.AreSame(descE, descriptors [4], "#D5"); Assert.AreSame(descF, descriptors [5], "#D6"); Assert.AreSame(descB, sorted [0], "#E1"); Assert.AreSame(descD, sorted [1], "#E2"); Assert.AreSame(descC, sorted [2], "#E3"); Assert.AreSame(descE, sorted [3], "#E4"); Assert.AreSame(descA, sorted [4], "#E5"); Assert.AreSame(descF, sorted [5], "#E6"); }
/// <summary> /// 获取由值参数指定的对象类型的属性集合 /// </summary> /// <param name="context">一个 System.ComponentModel.ITypeDescriptorContext,用于提供格式上下文</param> /// <param name="value">System.Object ,它指定要获取其属性的对象类型</param> /// <param name="attributes">类型的数组 System.Attribute ,将用作筛选器</param> /// <returns>一个 System.ComponentModel.PropertyDescriptorCollection 与组件公开的属性或 null 是否存在任何属性</returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { if (context == null || context.Instance == null) { return(base.GetProperties(context, value, attributes)); } PropertyDescriptorCollection pdc = base.GetProperties(context, value, attributes); string[] orderedPropertyNames; if (context.Instance.GetType().GetInterface(typeof(IPropertyGridOrder).FullName) != null) { IPropertyGridOrder propertyGridOrder = (IPropertyGridOrder)context.Instance; if (propertyGridOrder.OrderType == PropertyGridOrderType.Custom) { var srcOrderedPropertyNames = new List <string>(); foreach (PropertyDescriptor pd in pdc) { srcOrderedPropertyNames.Add(pd.Name); } orderedPropertyNames = propertyGridOrder.GetCustomSortPropertyName(srcOrderedPropertyNames); } else { orderedPropertyNames = this.GetOrderedPropertyNames(pdc, propertyGridOrder.OrderType == PropertyGridOrderType.Ascending); } } else { orderedPropertyNames = this.GetOrderedPropertyNames(pdc, true); } return(pdc.Sort(orderedPropertyNames)); }
/// <summary> /// プロパティ情報(<paramref name="value"/>)からプロパティのコレクションを取得し、 /// ローカライズ対応のための(<see cref="LocalizablePropertyDescriptor{TResources}"/>)型に /// 変換して返却する /// </summary> /// <param name="context"> /// 書式指定コンテキストを提供する <see cref="ITypeDescriptorContext"/> オブジェクト /// </param> /// <param name="value"> /// プロパティ情報(<see cref="PropertyInfo"/>)の取得対象となる配列のオブジェクト /// </param> /// <param name="attributes"> /// フィルターとして使用される、<see cref="Attribute"/> 型の配列 /// </param> /// <exception cref="NotSupportedException"> /// 引数の<paramref name="value"/> がプロセス間のリモートオブジェクトの場合に発生 /// </exception> /// <returns> /// 指定されたデータ型に対して公開されているプロパティを格納している、 /// ローカライズに対応した <see cref="PropertyDescriptor"/> のコレクション /// プロパティが格納されていない場合はNULL /// </returns> public override PropertyDescriptorCollection GetProperties( ITypeDescriptorContext context, object value, Attribute[] attributes) { // 基底クラスのメソッドからPropertyDescriptorコレクションを取得 PropertyDescriptorCollection properies = TypeDescriptor.GetProperties(value, attributes, true); if (properies == null) { // 取得できない場合はNULLを返却 return(null); } // ローカライズ可能なPropertyDescriptorに変換する PropertyDescriptorCollection returnCollection = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor property in properies) { returnCollection.Add(new LocalizablePropertyDescriptor <TResouces>(property)); } // リフレクションが定義順に取得することを利用し、定義順のソート条件を生成する List <string> sortList = new List <string>(); foreach (PropertyInfo propertyInfo in value?.GetType().GetProperties() ?? new PropertyInfo[0]) { sortList.Add(propertyInfo.Name); } // ローカライズ可能なPropertyDescriptorをプロパティの定義順にソートして返却する return(returnCollection.Sort(sortList.ToArray())); }
private void Pdc(T o) { // 获取子类型实例,否则为空.( typeof(T) -> o.GetType())) PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(o.GetType(), new Attribute[] { new BrowsableAttribute(true) }); PropertyCollection = (IsColSort ? pdc.Sort() : pdc); }
/// <summary> /// Returns the PropertyDescriptorCollection that represents the properties on each item used to bind data. /// </summary> /// <param name="listAccessors">An array of PropertyDescriptor objects to find in the collection as bindable. This can be a null reference.</param> /// <returns>The PropertyDescriptorCollection that represents the properties on each item used to bind data.</returns> internal PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { PropertyDescriptorCollection m_OriginalList = TypeDescriptor.GetProperties(typeof(DaItem)); PropertyDescriptorCollection m_SortedList = m_OriginalList.Sort(new string[] {}); return(m_SortedList); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { //get the property collection of the object (Item class), by default the rendering on the "Properties Window" is alphabetically PropertyDescriptorCollection propertyDescriptorCollection = TypeDescriptor.GetProperties(value, attributes); //dictionary that will store the property and CustomOrder's value Dictionary <PropertyDescriptor, int> propertyAndOrderCollection = new Dictionary <PropertyDescriptor, int>(); foreach (PropertyDescriptor propertyDescriptor in propertyDescriptorCollection) { //get the CustomOrder attribute set on the property Attribute customOrderAttribute = propertyDescriptor.Attributes[typeof(CustomOrderAttribute)]; //get the "Value" of the attribute if attribute was not set give it a zero value int customOrderValue = (customOrderAttribute == null) ? 0 : (customOrderAttribute as CustomOrderAttribute).Value; //store the property and CustomOrder's value in the dictionary propertyAndOrderCollection.Add(propertyDescriptor, customOrderValue); } //sort the property and CustomOrder collection and store it to a new dictionary of string and int Dictionary <string, int> sortedProperty = propertyAndOrderCollection. OrderBy(x => x.Value). //sort by CustomOrder first ThenBy(y => y.Key.Name). //then sort by Property Name ToDictionary(z => z.Key.Name, z => z.Value); //Dictionary<string, int> instead of <PropertyDescriptor, int> //return the sorted property collection which will be rendered in the "Properties Window" return(propertyDescriptorCollection.Sort(sortedProperty.Keys.ToArray())); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value, attributes); ArrayList arrayList1 = new ArrayList(); foreach (PropertyDescriptor propertyDescriptor in properties) { Attribute attribute = propertyDescriptor.Attributes[typeof(PropertyOrderAttribute)]; if (attribute != null) { PropertyOrderAttribute propertyOrderAttribute = (PropertyOrderAttribute)attribute; arrayList1.Add((object)new PropertyOrderPair(propertyDescriptor.Name, propertyOrderAttribute.Order)); } else { arrayList1.Add((object)new PropertyOrderPair(propertyDescriptor.Name, 0)); } } arrayList1.Sort(); ArrayList arrayList2 = new ArrayList(); foreach (PropertyOrderPair propertyOrderPair in arrayList1) { arrayList2.Add((object)propertyOrderPair.Name); } return(properties.Sort((string[])arrayList2.ToArray(typeof(string)))); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="value"></param> /// <param name="attributes"></param> /// <returns></returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, System.Attribute[] attributes) { PropertyDescriptorCollection collection1 = TypeDescriptor.GetProperties(typeof(TabMargins), attributes); string[] textArray1 = new string[] { "Left", "Top", "Right", "Bottom" }; return(collection1.Sort(textArray1)); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(ReportFont), attributes); string[] fontArray = new string[] { "FontStyle", "FontFamily", "FontSize", "FontWeight" }; return(properties.Sort(fontArray)); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(value, attributes); //排序 return(pdc.Sort(new string[] { "X", "Y", "Width", "Height" })); }
/// <include file='doc\AutomationExtenderManager.uex' path='docs/doc[@for="ExtendedObjectWrapper.CreateExtendedProperties"]/*' /> /// <devdoc> /// Creates the extended descriptors for an object given a list of extenders /// and property names. /// </devdoc> private Hashtable CreateExtendedProperties(Hashtable extenderList) { string[] keys = new string[extenderList.Keys.Count]; extenderList.Keys.CopyTo(keys, 0); Hashtable extenders = new Hashtable(); for (int i = 0; i < keys.Length; i++) { string name = keys[i]; object extender = extenderList[name]; PropertyDescriptorCollection props = TypeDescriptor.GetProperties(extender, new Attribute[] { BrowsableAttribute.Yes }); props.Sort(); if (props != null) { for (int p = 0; p < props.Count; p++) { #if DEBUG string pname = props[p].Name; Debug.Assert(extenders[pname] == null, "multiple extenders of name '" + pname + "' detected"); #endif extenders[props[p].Name] = new ExtenderItem(props[p], extender); } } } return(extenders); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection descriptors = new PropertyDescriptorCollection(null); descriptors.Add(new RuleConditionReferenceNamePropertyDescriptor(context, TypeDescriptor.CreateProperty(typeof(RuleConditionReference), "ConditionName", typeof(string), new Attribute[] { new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content), DesignOnlyAttribute.Yes }))); descriptors.Add(new RuleConditionReferencePropertyDescriptor(context, TypeDescriptor.CreateProperty(typeof(RuleConditionReference), "Expression", typeof(CodeExpression), new Attribute[] { new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content), DesignOnlyAttribute.Yes }))); return(descriptors.Sort(new string[] { "ConditionName", "Expression" })); }
/// <summary> /// Returns a collection of properties for the type of object specified by the value parameter using the /// specified context and attributes. /// </summary> /// <param name="context">A formatter context</param> /// <param name="value">The object for which to get properties</param> /// <param name="attributes">An array of attributes that describe the properties</param> /// <returns>The set of properties that should be exposed for this data type</returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(typeof(ListPadding), attributes); string[] props = new[] { "Top", "Left", "Bottom", "Right", "Column", "Row" }; return(pdc.Sort(props)); }
/// <summary> /// renvoi la liste des propriétés disponible pour l'inspecteur de propriétés /// </summary> /// <param name="context"></param> /// <param name="value"></param> /// <param name="attributes"></param> /// <returns></returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, System.Attribute[] attributes) { PropertyDescriptorCollection collection1 = TypeDescriptor.GetProperties(typeof(GeniusLinearGradientBrush), attributes); string[] textArray1 = new string[3] { "Angle", "BeginColor", "EndColor" }; return(collection1.Sort(textArray1)); }