/// <include file='doc\RepeaterDesigner.uex' path='docs/doc[@for="RepeaterDesigner.PreFilterProperties"]/*' /> /// <devdoc> /// Filter the properties to replace the runtime DataSource property /// descriptor with the designer's. /// </devdoc> protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); PropertyDescriptor prop; prop = (PropertyDescriptor)properties["DataSource"]; Debug.Assert(prop != null); // we can't create the designer DataSource property based on the runtime property since theie // types do not match. Therefore, we have to copy over all the attributes from the runtime // and use them that way. AttributeCollection runtimeAttributes = prop.Attributes; Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new TypeConverterAttribute(typeof(DataSourceConverter)); prop = TypeDescriptor.CreateProperty(this.GetType(), "DataSource", typeof(string), attrs); properties["DataSource"] = prop; prop = (PropertyDescriptor)properties["DataMember"]; Debug.Assert(prop != null); prop = TypeDescriptor.CreateProperty(this.GetType(), prop, new Attribute[] { new TypeConverterAttribute(typeof(DataMemberConverter)) }); properties["DataMember"] = prop; }
internal static void AddAttributesToPropertiesOfDifferentType( Type designerType, Type newType, IDictionary properties, String propertyName, Attribute newAttribute) { Debug.Assert(propertyName != null && propertyName.Length != 0); PropertyDescriptor prop = (PropertyDescriptor)properties[propertyName]; Debug.Assert(prop != null); // we can't create the designer DataSource property based on the runtime property since their // types do not match. Therefore, we have to copy over all the attributes from the runtime // and use them that way. System.ComponentModel.AttributeCollection runtimeAttributes = prop.Attributes; Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = newAttribute; prop = TypeDescriptor.CreateProperty( designerType, propertyName, newType, attrs); properties[propertyName] = prop; }
private List <PropertyDescriptor> GetPropertyDescriptor(SearchHelper helper) { List <PropertyDescriptor> returnProp = new List <PropertyDescriptor>(); var properties = TypeDescriptor.GetProperties(helper.SearchType); foreach (PropertyDescriptor propDes in properties) { PropertyDescriptor property = propDes; if (helper.HideColumns.Contains(propDes.Name)) { if (property != null) { System.ComponentModel.AttributeCollection runtimeAttributes = property.Attributes; // make a copy of the original attributes // but make room for one extra attribute Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new BrowsableAttribute(false); // makes this Property hidden in PropertyGrid property = TypeDescriptor.CreateProperty(this.GetType(), property.Name, property.PropertyType, attrs); } } returnProp.Add(property); } return(returnProp); }
protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); PropertyDescriptor propertyDescriptor = (PropertyDescriptor)properties["DataSource"]; if (null != propertyDescriptor) { System.ComponentModel.AttributeCollection runtimeAttributes = propertyDescriptor.Attributes; Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new TypeConverterAttribute(typeof(DataSourceConverter)); propertyDescriptor = TypeDescriptor.CreateProperty(this.GetType(), "DataSource", typeof(string), attrs); properties["DataSource"] = propertyDescriptor; } propertyDescriptor = (PropertyDescriptor)properties["DataMember"]; if (null != propertyDescriptor) { System.ComponentModel.AttributeCollection runtimeAttributes = propertyDescriptor.Attributes; Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new TypeConverterAttribute(typeof(DataMemberConverter)); propertyDescriptor = TypeDescriptor.CreateProperty(this.GetType(), "DataMember", typeof(string), attrs); properties["DataMember"] = propertyDescriptor; } }
protected override void PreFilterProperties(IDictionary properties) { int num2; base.PreFilterProperties(properties); PropertyDescriptor oldPropertyDescriptor = (PropertyDescriptor)properties["DataSource"]; System.ComponentModel.AttributeCollection attributes = oldPropertyDescriptor.Attributes; int index = -1; int count = attributes.Count; string dataSource = this.DataSource; if (dataSource.Length > 0) { this._keepDataSourceBrowsable = true; } for (int i = 0; i < attributes.Count; i++) { if (attributes[i] is BrowsableAttribute) { index = i; break; } } if (((index == -1) && (dataSource.Length == 0)) && !this._keepDataSourceBrowsable) { num2 = count + 2; } else { num2 = count + 1; } Attribute[] array = new Attribute[num2]; attributes.CopyTo(array, 0); array[count] = new TypeConverterAttribute(typeof(DataSourceConverter)); if ((dataSource.Length == 0) && !this._keepDataSourceBrowsable) { if (index == -1) { array[count + 1] = BrowsableAttribute.No; } else { array[index] = BrowsableAttribute.No; } } oldPropertyDescriptor = TypeDescriptor.CreateProperty(base.GetType(), "DataSource", typeof(string), array); properties["DataSource"] = oldPropertyDescriptor; oldPropertyDescriptor = (PropertyDescriptor)properties["DataMember"]; oldPropertyDescriptor = TypeDescriptor.CreateProperty(base.GetType(), oldPropertyDescriptor, new Attribute[] { new TypeConverterAttribute(typeof(DataMemberConverter)) }); properties["DataMember"] = oldPropertyDescriptor; oldPropertyDescriptor = (PropertyDescriptor)properties["DataKeyField"]; oldPropertyDescriptor = TypeDescriptor.CreateProperty(base.GetType(), oldPropertyDescriptor, new Attribute[] { new TypeConverterAttribute(typeof(DataFieldConverter)) }); properties["DataKeyField"] = oldPropertyDescriptor; oldPropertyDescriptor = (PropertyDescriptor)properties["DataSourceID"]; oldPropertyDescriptor = TypeDescriptor.CreateProperty(base.GetType(), oldPropertyDescriptor, new Attribute[] { new TypeConverterAttribute(typeof(DataSourceIDConverter)) }); properties["DataSourceID"] = oldPropertyDescriptor; }
/// <summary> /// Used to modify the Attributes of the 'Data' related fields such that /// the correct TypeConverters are added to the Attributes. For some reason /// adding the attributes directly doesn't work. /// </summary> /// <param name="properties">The dictionary</param> protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); PropertyDescriptor prop = (PropertyDescriptor)properties["DataSource"]; if (prop != null) { System.ComponentModel.AttributeCollection runtimeAttributes = prop.Attributes; // make a copy of the original attributes but make room for one extra attribute ie the TypeConverter attribute Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new TypeConverterAttribute(typeof(DataSourceConverter)); prop = TypeDescriptor.CreateProperty(this.GetType(), "DataSource", typeof(string), attrs); properties["DataSource"] = prop; } prop = (PropertyDescriptor)properties["DataMember"]; if (prop != null) { System.ComponentModel.AttributeCollection runtimeAttributes = prop.Attributes; Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; // make a copy of the original attributes but make room for one extra attribute ie the TypeConverter attribute runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new TypeConverterAttribute(typeof(DataMemberConverter)); prop = TypeDescriptor.CreateProperty(this.GetType(), "DataMember", typeof(string), attrs); properties["DataMember"] = prop; } prop = (PropertyDescriptor)properties["DataValueField"]; if (prop != null) { System.ComponentModel.AttributeCollection runtimeAttributes = prop.Attributes; Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; // make a copy of the original attributes but make room for one extra attribute ie the TypeConverter attribute runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new TypeConverterAttribute(typeof(DataFieldConverter)); prop = TypeDescriptor.CreateProperty(this.GetType(), "DataValueField", typeof(string), attrs); properties["DataValueField"] = prop; } prop = (PropertyDescriptor)properties["DataTextField"]; if (prop != null) { System.ComponentModel.AttributeCollection runtimeAttributes = prop.Attributes; Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1]; // make a copy of the original attributes but make room for one extra attribute ie the TypeConverter attribute runtimeAttributes.CopyTo(attrs, 0); attrs[runtimeAttributes.Count] = new TypeConverterAttribute(typeof(DataFieldConverter)); prop = TypeDescriptor.CreateProperty(this.GetType(), "DataTextField", typeof(string), attrs); properties["DataTextField"] = prop; } }
protected override void PreFilterProperties(IDictionary properties) { int num2; base.PreFilterProperties(properties); PropertyDescriptor descriptor = (PropertyDescriptor)properties["DataSource"]; System.ComponentModel.AttributeCollection attributes = descriptor.Attributes; int index = -1; int count = attributes.Count; string dataSource = this.DataSource; bool flag = (dataSource != null) && (dataSource.Length > 0); if (flag) { this._keepDataSourceBrowsable = true; } for (int i = 0; i < attributes.Count; i++) { if (attributes[i] is BrowsableAttribute) { index = i; break; } } if (((index == -1) && !flag) && !this._keepDataSourceBrowsable) { num2 = count + 1; } else { num2 = count; } Attribute[] array = new Attribute[num2]; attributes.CopyTo(array, 0); if (!flag && !this._keepDataSourceBrowsable) { if (index == -1) { array[count] = BrowsableAttribute.No; } else { array[index] = BrowsableAttribute.No; } } descriptor = TypeDescriptor.CreateProperty(base.GetType(), "DataSource", typeof(string), array); properties["DataSource"] = descriptor; }
public static AttributeCollection FromExisting(AttributeCollection existing, params Attribute[] newAttributes) { if (existing == null) { throw new ArgumentNullException("existing"); } if (newAttributes == null) { newAttributes = new Attribute[0]; } Attribute[] array = new Attribute[existing.Count + newAttributes.Length]; int count = existing.Count; existing.CopyTo(array, 0); for (int i = 0; i < newAttributes.Length; i++) { if (newAttributes[i] == null) { throw new ArgumentNullException("newAttributes"); } bool flag = false; for (int j = 0; j < existing.Count; j++) { if (array[j].TypeId.Equals(newAttributes[i].TypeId)) { flag = true; array[j] = newAttributes[i]; break; } } if (!flag) { array[count++] = newAttributes[i]; } } Attribute[] destinationArray = null; if (count < array.Length) { destinationArray = new Attribute[count]; Array.Copy(array, 0, destinationArray, 0, count); } else { destinationArray = array; } return new AttributeCollection(destinationArray); }
static Attribute[] GetAttribs(AttributeCollection value) { if (value == null) return null; Attribute[] result = new Attribute[value.Count]; value.CopyTo(result, 0); return result; }
/// <summary> /// Creates an Attribute array from an AttributeCollection instance /// </summary> /// <param name="collection"></param> /// <returns></returns> private static Attribute[] AttributeCollectionToArray(AttributeCollection collection) { Attribute[] array = new Attribute[collection.Count]; collection.CopyTo(array, 0); return array; }
internal Attribute[] GetAttributesFromCollection(AttributeCollection collection) { Attribute[] attributes = new Attribute[collection.Count]; collection.CopyTo(attributes, 0); return attributes; }
private Attribute[] GetAttributesFromCollection(AttributeCollection collection) { Attribute[] array = new Attribute[collection.Count]; collection.CopyTo(array, 0); return array; }
private PropertyDescriptorCollection GetProperties (object propertyOwner, AttributeCollection attributes) { if (propertyOwner == null || property_grid.SelectedTab == null) return new PropertyDescriptorCollection (null); Attribute[] atts = new Attribute[attributes.Count]; attributes.CopyTo (atts, 0); return property_grid.SelectedTab.GetProperties ((ITypeDescriptorContext)this, propertyOwner, atts); }
/// <devdoc> /// Creates a new AttributeCollection from an existing AttributeCollection /// </devdoc> public static AttributeCollection FromExisting(AttributeCollection existing, params Attribute[] newAttributes) { if (existing == null) { throw new ArgumentNullException("existing"); } if (newAttributes == null) { newAttributes = new Attribute[0]; } Attribute[] newArray = new Attribute[existing.Count + newAttributes.Length]; int actualCount = existing.Count; existing.CopyTo(newArray, 0); for (int idx = 0; idx < newAttributes.Length; idx++) { if (newAttributes[idx] == null) { throw new ArgumentNullException("newAttributes"); } // We must see if this attribute is already in the existing // array. If it is, we replace it. bool match = false; for (int existingIdx = 0; existingIdx < existing.Count; existingIdx++) { if (newArray[existingIdx].TypeId.Equals(newAttributes[idx].TypeId)) { match = true; newArray[existingIdx] = newAttributes[idx]; break; } } if (!match) { newArray[actualCount++] = newAttributes[idx]; } } // Now, if we collapsed some attributes, create a new array. // Attribute[] attributes = null; if (actualCount < newArray.Length) { attributes = new Attribute[actualCount]; Array.Copy(newArray, 0, attributes, 0, actualCount); } else { attributes = newArray; } return new AttributeCollection(attributes); }
/// <summary> /// Retrieves custom attributes. /// </summary> internal AttributeCollection GetAttributes() { // Worst case collision scenario: we don't want the perf hit // of taking a lock, so if we collide we will query for // attributes twice. Not a big deal. if (_attributes == null) { // Obtaining attributes follows a very critical order: we must take care that // we merge attributes the right way. Consider this: // // [A4] // interface IBase; // // [A3] // interface IDerived; // // [A2] // class Base : IBase; // // [A1] // class Derived : Base, IDerived // // Calling GetAttributes on type Derived must merge attributes in the following // order: A1 - A4. Interfaces always lose to types, and interfaces and types // must be merged in the same order. At the same time, we must be careful // that we don't always go through reflection here, because someone could have // created a custom provider for a type. Because there is only one instance // of ReflectTypeDescriptionProvider created for typeof(object), if our code // is invoked here we can be sure that there is no custom provider for // _type all the way up the base class chain. // We cannot be sure that there is no custom provider for // interfaces that _type implements, however, because they are not derived // from _type. So, for interfaces, we must go through TypeDescriptor // again to get the interfaces attributes. // Get the type's attributes. This does not recurse up the base class chain. // We append base class attributes to this array so when walking we will // walk from Length - 1 to zero. // Attribute[] attrArray = ReflectGetAttributes(_type); Type baseType = _type.BaseType; while (baseType != null && baseType != typeof(object)) { Attribute[] baseArray = ReflectGetAttributes(baseType); Attribute[] temp = new Attribute[attrArray.Length + baseArray.Length]; Array.Copy(attrArray, 0, temp, 0, attrArray.Length); Array.Copy(baseArray, 0, temp, attrArray.Length, baseArray.Length); attrArray = temp; baseType = baseType.BaseType; } // Next, walk the type's interfaces. We append these to // the attribute array as well. int ifaceStartIdx = attrArray.Length; Type[] interfaces = _type.GetInterfaces(); for (int idx = 0; idx < interfaces.Length; idx++) { Type iface = interfaces[idx]; // Only do this for public interfaces. if ((iface.Attributes & (TypeAttributes.Public | TypeAttributes.NestedPublic)) != 0) { // No need to pass an instance into GetTypeDescriptor here because, if someone provided a custom // provider based on object, it already would have hit. AttributeCollection ifaceAttrs = TypeDescriptor.GetAttributes(iface); if (ifaceAttrs.Count > 0) { Attribute[] temp = new Attribute[attrArray.Length + ifaceAttrs.Count]; Array.Copy(attrArray, 0, temp, 0, attrArray.Length); ifaceAttrs.CopyTo(temp, attrArray.Length); attrArray = temp; } } } // Finally, put all these attributes in a dictionary and filter out the duplicates. OrderedDictionary attrDictionary = new OrderedDictionary(attrArray.Length); for (int idx = 0; idx < attrArray.Length; idx++) { bool addAttr = true; if (idx >= ifaceStartIdx) { for (int ifaceSkipIdx = 0; ifaceSkipIdx < s_skipInterfaceAttributeList.Length; ifaceSkipIdx++) { if (s_skipInterfaceAttributeList[ifaceSkipIdx].IsInstanceOfType(attrArray[idx])) { addAttr = false; break; } } } if (addAttr && !attrDictionary.Contains(attrArray[idx].TypeId)) { attrDictionary[attrArray[idx].TypeId] = attrArray[idx]; } } attrArray = new Attribute[attrDictionary.Count]; attrDictionary.Values.CopyTo(attrArray, 0); _attributes = new AttributeCollection(attrArray); } return(_attributes); }
/// <summary> /// Creates a new AttributeCollection from an existing AttributeCollection /// </summary> public static AttributeCollection FromExisting(AttributeCollection existing, params Attribute[] newAttributes) { // VSWhidbey #75418 // This method should be a constructor, but making it one introduces a breaking change. // if (existing == null) { throw new ArgumentNullException(nameof(existing)); } if (newAttributes == null) { newAttributes = Array.Empty <Attribute>(); } Attribute[] newArray = new Attribute[existing.Count + newAttributes.Length]; int actualCount = existing.Count; existing.CopyTo(newArray, 0); for (int idx = 0; idx < newAttributes.Length; idx++) { if (newAttributes[idx] == null) { throw new ArgumentNullException(nameof(newAttributes)); } // We must see if this attribute is already in the existing // array. If it is, we replace it. bool match = false; for (int existingIdx = 0; existingIdx < existing.Count; existingIdx++) { if (newArray[existingIdx].TypeId.Equals(newAttributes[idx].TypeId)) { match = true; newArray[existingIdx] = newAttributes[idx]; break; } } if (!match) { newArray[actualCount++] = newAttributes[idx]; } } // Now, if we collapsed some attributes, create a new array. // Attribute[] attributes = null; if (actualCount < newArray.Length) { attributes = new Attribute[actualCount]; Array.Copy(newArray, 0, attributes, 0, actualCount); } else { attributes = newArray; } return(new AttributeCollection(attributes)); }
public void CopyTo(Attribute[] target, int startIndex) { _attributes.CopyTo(target, startIndex); }
/// <summary> /// Creates a new AttributeCollection from an existing AttributeCollection /// </summary> public static AttributeCollection FromExisting(AttributeCollection existing, params Attribute[] newAttributes) { // VSWhidbey #75418 // This method should be a constructor, but making it one introduces a breaking change. // if (existing == null) { throw new ArgumentNullException(nameof(existing)); } if (newAttributes == null) { newAttributes = Array.Empty<Attribute>(); } Attribute[] newArray = new Attribute[existing.Count + newAttributes.Length]; int actualCount = existing.Count; existing.CopyTo(newArray, 0); for (int idx = 0; idx < newAttributes.Length; idx++) { if (newAttributes[idx] == null) { throw new ArgumentNullException(nameof(newAttributes)); } // We must see if this attribute is already in the existing // array. If it is, we replace it. bool match = false; for (int existingIdx = 0; existingIdx < existing.Count; existingIdx++) { if (newArray[existingIdx].TypeId.Equals(newAttributes[idx].TypeId)) { match = true; newArray[existingIdx] = newAttributes[idx]; break; } } if (!match) { newArray[actualCount++] = newAttributes[idx]; } } // Now, if we collapsed some attributes, create a new array. // Attribute[] attributes = null; if (actualCount < newArray.Length) { attributes = new Attribute[actualCount]; Array.Copy(newArray, 0, attributes, 0, actualCount); } else { attributes = newArray; } return new AttributeCollection(attributes); }