public void FromExisting_NullNewAttributes_Success() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var existingAttributes = new Attribute[] { attribute1, attribute2 }; var existing = new AttributeCollection(existingAttributes); var collection = AttributeCollection.FromExisting(existing, null); Assert.Equal(existingAttributes, collection.Cast <Attribute>()); }
public static BrowsableItem <T> Create(T item) { BrowsableAttribute browsable = Util.GetAttribute <BrowsableAttribute>(item, false); if (browsable != null && !browsable.Browsable) { return(null); } return(new BrowsableItem <T>(item)); }
protected void ShowHide(string field, bool value) { try { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.GetType())[field]; BrowsableAttribute theDescriptorBrowsableAttribute = (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)]; FieldInfo isBrowsable = theDescriptorBrowsableAttribute.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance); isBrowsable.SetValue(theDescriptorBrowsableAttribute, value); } catch (Exception) { Console.WriteLine($"Show/Hide Issue for {field}"); } }
public override bool Equals(object obj) { if (obj == this) { return(true); } BrowsableAttribute other = obj as BrowsableAttribute; return(other?.Browsable == Browsable); }
private void HideShowProperty(string property, bool show) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.GetType())[property]; BrowsableAttribute attrib = (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)]; FieldInfo isBrow = attrib.GetType().GetField("browsable", BindingFlags.NonPublic | BindingFlags.Instance); isBrow.SetValue(attrib, show); }
public static bool IsBrowsable(this MemberInfo source) { BrowsableAttribute att = source.GetCustomAttributes(false).OfType <BrowsableAttribute>().FirstOrDefault(); if (att != null) { return(att.Browsable); } return(true); }
public void SetIsBrowsable(bool isBrowsable) { var attr = (BrowsableAttribute)attributes.FirstOrDefault(a => a is BrowsableAttribute); if (attr != null) { attributes.RemoveAll(a => a is BrowsableAttribute); } attr = new BrowsableAttribute(isBrowsable); attributes.Add(attr); }
/// <summary> /// </summary> public override bool Equals(object obj) { if (obj == this) { return(true); } BrowsableAttribute other = obj as BrowsableAttribute; return((other != null) && other.Browsable == _browsable); }
protected void SetBrowsable(string property, bool value) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.GetType())[property]; BrowsableAttribute attribute = (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)]; Type gtype = attribute.GetType(); FieldInfo[] fields = attribute.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance); Debug.Assert(fields.Length == 1); FieldInfo fieldToChange = fields[0]; fieldToChange.SetValue(attribute, value); }
public void Contains_InvokeAttributeWithAttributes_ReturnsExpected() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var collection = new AttributeCollection(attribute1, attribute2); Assert.True(collection.Contains(attribute1)); Assert.False(collection.Contains(new BrowsableAttribute(false))); Assert.True(collection.Contains(attribute2)); Assert.False(collection.Contains(new EditorBrowsableAttribute())); Assert.False(collection.Contains((Attribute)null)); }
/// <summary> /// Set the Browsable property. /// NOTE: Be sure to decorate the property with [Browsable(true)] /// </summary> /// <param name="PropertyName">Name of the variable</param> /// <param name="bIsBrowsable">Browsable Value</param> public void setBrowsableProperty(string strPropertyName, bool bIsBrowsable) { // Get the Descriptor's Properties PropertyDescriptor theDescriptor = TypeDescriptor.GetProperties(this.GetType())[strPropertyName]; // Get the Descriptor's "Browsable" Attribute BrowsableAttribute theDescriptorBrowsableAttribute = (BrowsableAttribute)theDescriptor.Attributes[typeof(BrowsableAttribute)]; FieldInfo isBrowsable = theDescriptorBrowsableAttribute.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance); // Set the Descriptor's "Browsable" Attribute isBrowsable.SetValue(theDescriptorBrowsableAttribute, bIsBrowsable); }
public static IEnumerable <object[]> Ctor_Attributes_TestData() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); yield return(new object[] { new Attribute[] { attribute1, attribute2 }, new Attribute[] { attribute1, attribute2 } }); yield return(new object[] { new Attribute[] { attribute1 }, new Attribute[] { attribute1 } }); yield return(new object[] { new Attribute[0], new Attribute[0] }); yield return(new object[] { null, new Attribute[0] }); }
/// <summary> /// Checks if given enumerator value has Browsable attribute and is set to False, /// else returns True. /// </summary> /// <param name="value">Enumerator value.</param> /// <returns>true if member is browsable; otherwise, returns false.</returns> public static bool GetEnumBrowsable(Enum value) { BrowsableAttribute attr = GetAttribute <BrowsableAttribute>(value); if (attr != null) { return(attr.Browsable); } else { return(true); } }
/// <summary> /// Overridden. Inherited from <see cref="ControlDesigner.PreFilterProperties(IDictionary)"/>. /// </summary> /// <param name="properties"></param> protected override void PreFilterProperties(IDictionary properties) { Attribute[] attr = new Attribute[3]; attr[0] = new BrowsableAttribute(true); attr[1] = new CategoryAttribute("Custom"); attr[2] = new EditorBrowsableAttribute(); //properties["ActiveTextColor"] = TypeDescriptor.CreateProperty(typeof(ImageTabPageDesigner), (PropertyDescriptor)properties["ActiveTextColor"], attr); //properties["InactiveTextColor"] = TypeDescriptor.CreateProperty(typeof(ImageTabPageDesigner), (PropertyDescriptor)properties["InactiveTextColor"], attr); base.PreFilterProperties(properties); }
public void FromExisting_SameNewAttributes_Success() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var attribute3 = new EditorBrowsableAttribute(EditorBrowsableState.Never); var existingAttributes = new Attribute[] { attribute1, attribute2 }; var newAttributes = new Attribute[] { attribute2, attribute3 }; var existing = new AttributeCollection(existingAttributes); var collection = AttributeCollection.FromExisting(existing, newAttributes); Assert.Equal(new Attribute[] { existingAttributes[0], newAttributes[0], newAttributes[1] }, collection.Cast <Attribute>()); }
// Determine if two instances of this class are equal. public override bool Equals(Object obj) { BrowsableAttribute other = (obj as BrowsableAttribute); if (other != null) { return(browse == other.browse); } else { return(false); } }
private bool IsPropertyBrowsable(string propertyName) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.currentItem)[propertyName]; if (descriptor != null) { BrowsableAttribute attribute = descriptor.Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute; if (attribute != null) { return(attribute.Browsable); } } return(true); }
public void FromExisting_DifferentNewAttributes_Success() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var attribute3 = new EditorBrowsableAttribute(EditorBrowsableState.Never); var attribute4 = new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content); var existingAttributes = new Attribute[] { attribute1, attribute2 }; var newAttributes = new Attribute[] { attribute3, attribute4 }; var existing = new AttributeCollection(existingAttributes); var collection = AttributeCollection.FromExisting(existing, newAttributes); Assert.Equal(existingAttributes.Concat(newAttributes), collection.Cast <Attribute>()); }
private bool A(PropertyInfo propertyInfo) { BrowsableAttribute[] array = (BrowsableAttribute[])propertyInfo.GetCustomAttributes(typeof(BrowsableAttribute), true); BrowsableAttribute[] array2 = array; for (int i = 0; i < array2.Length; i++) { BrowsableAttribute browsableAttribute = array2[i]; if (!browsableAttribute.Browsable) { return(false); } } return(true); }
public RABBITIN(XmlNode dataModel, IView view) { this._node = dataModel; this.view = view; this.type = "RABBITDEFEX"; // The "Priority Propery is only for input, so make sure it is set correctly PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.GetType())["Priority"]; BrowsableAttribute theDescriptorBrowsableAttribute = (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)]; FieldInfo isBrowsable = theDescriptorBrowsableAttribute.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance); // Set the Descriptor's "Browsable" Attribute isBrowsable.SetValue(theDescriptorBrowsableAttribute, true); }
public void Ctor_ModifyAttributes_UpdatesInnerArray() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var attributes = new Attribute[] { attribute1 }; var collection = new SubAttributeCollection(attributes); Assert.Equal(attributes, collection.Attributes); Assert.Equal(new Attribute[] { attribute1 }, collection.Cast <Attribute>()); // Change. attributes[0] = attribute2; Assert.Equal(new Attribute[] { attribute2 }, collection.Cast <Attribute>()); }
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] filter) { Type proxyType = proxy.GetType(); Type[] interfaces = proxyType.GetInterfaces(); Hashtable allProerties = new Hashtable(); PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties(proxy.GetType()); foreach (PropertyDescriptor propDesc in baseProps) { allProerties.Add(propDesc.Name, propDesc); } foreach (Type interfaceType in interfaces) { PropertyDescriptorCollection ifaceProps = TypeDescriptor.GetProperties(interfaceType); foreach (PropertyDescriptor propDesc in ifaceProps) { PropertyInfo propInfo = interfaceType.GetProperty(propDesc.Name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); object[] customAttribs = propInfo.GetCustomAttributes(typeof(BrowsableAttribute), true); if (customAttribs.Length > 0) { BrowsableAttribute browsable = (BrowsableAttribute)customAttribs[0]; if (browsable.Browsable) { if (!allProerties.ContainsKey(propDesc.Name)) { allProerties.Add(propDesc.Name, propDesc); } } } } } PropertyDescriptor[] allPropertiesArray = new PropertyDescriptor[allProerties.Count]; int i = 0; foreach (PropertyDescriptor propDesc in allProerties.Values) { allPropertiesArray[i] = propDesc; i++; } return(new PropertyDescriptorCollection(allPropertiesArray)); }
public static void CheckMembersVisibility(ITypesInfo typesInfo, Type type, IList <String> visibleMembers) { ITypeInfo typeInfo = typesInfo.FindTypeInfo(type); foreach (IMemberInfo memberInfo in typeInfo.Members) { BrowsableAttribute browsableAttribute = memberInfo.FindAttribute <BrowsableAttribute>(); if ((browsableAttribute == null) || browsableAttribute.Browsable) { String message = String.Format( "The '{0}.{1}' member should be marked by the Browsable(false) attribute.", memberInfo.Owner.Name, memberInfo.Name); Assert.AreEqual(true, visibleMembers.Contains(memberInfo.Name), message); } } }
private bool IsBrowsable(Attribute[] attributes) { if (attributes != null && attributes.Length > 0) { for (int i = 0; i < attributes.Length; i++) { BrowsableAttribute ba = attributes[i] as BrowsableAttribute; if (ba != null) { return(ba.Browsable); } } } return(false); }
private static bool IsVisible(object enumValue) { Type type = enumValue.GetType(); MemberInfo[] memInfo = type.GetMember(enumValue.ToString()); if (memInfo != null && memInfo.Length > 0) { BrowsableAttribute _att = memInfo[0].GetCustomAttribute(typeof(BrowsableAttribute), false) as BrowsableAttribute; if (_att != null) { return(_att.Browsable); } } return(true); }
public void CopyTo_InvokeNotEmpty_Success() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var collection = new SubAttributeCollection(attribute1, attribute2); var array = new object[] { 1, 2, 3 }; collection.CopyTo(array, 0); Assert.Equal(new object[] { attribute1, attribute2, 3 }, array); array = new object[] { 1, 2, 3 }; collection.CopyTo(array, 1); Assert.Equal(new object[] { 1, attribute1, attribute2 }, array); }
public void Matches_InvokeAttributesWithAttributes_ReturnsExpected() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var collection = new AttributeCollection(attribute1, attribute2); Assert.True(collection.Matches(new Attribute[] { attribute1 })); Assert.False(collection.Matches(new Attribute[] { new BrowsableAttribute(false) })); Assert.True(collection.Matches(new Attribute[] { attribute1, attribute2 })); Assert.False(collection.Matches(new Attribute[] { attribute1, attribute2, new EditorBrowsableAttribute() })); Assert.False(collection.Matches(new Attribute[] { new EditorBrowsableAttribute() })); Assert.False(collection.Matches(new Attribute[] { null })); Assert.True(collection.Matches(new Attribute[0])); Assert.True(collection.Matches((Attribute[])null)); }
internal static void RegisterMetadata(AttributeTableBuilder builder) { Type endpointType = typeof(Endpoint); var browsableAttribute = new BrowsableAttribute(false); builder.AddCustomAttributes(endpointType, endpointType.GetProperty("BehaviorConfigurationName"), browsableAttribute); builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Headers"), browsableAttribute); builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Identity"), browsableAttribute); builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Name"), browsableAttribute); builder.AddCustomAttributes(endpointType, endpointType.GetProperty("ListenUri"), browsableAttribute); builder.AddCustomAttributes(endpointType, endpointType.GetProperty("ServiceContractName"), browsableAttribute); builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Binding"), PropertyValueEditor.CreateEditorAttribute(typeof(BindingPropertyValueEditor))); }
public bool SetDescription(object _src, PropertyInfo _pi_src, object _dst, PropertyInfo _pi_dst) { BrowsableAttribute ba_src = Attribute.GetCustomAttribute(_pi_src, typeof(BrowsableAttribute)) as BrowsableAttribute; if (!ba_src.Browsable) { PropertyDescriptor pd = TypeDescriptor.GetProperties(_pi_dst.DeclaringType)[_pi_dst.Name]; BrowsableAttribute ba = (BrowsableAttribute)pd.Attributes[typeof(BrowsableAttribute)]; if (ba != null) { FieldInfo isBrowsable = ba.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance); isBrowsable.SetValue(ba, false); } } return(true); }
protected void Method() { // <Snippet1> // Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this)["MyProperty"].Attributes; // Checks to see if the property is browsable. BrowsableAttribute myAttribute = (BrowsableAttribute)attributes[typeof(BrowsableAttribute)]; if (myAttribute.Browsable) { // Insert code here. } // </Snippet1> }
public void GetBrowsable(bool value) { var attribute = new BrowsableAttribute(value); Assert.Equal(value, attribute.Browsable); }
public void GetBrowsable(BrowsableAttribute attribute, bool expectedBrowsable) { Assert.Equal(expectedBrowsable, attribute.Browsable); }
PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors) { PropertyDescriptorCollection pdc; if (null == listAccessors) { pdc = new PropertyDescriptorCollection(null); BrowsableAttribute browsable = new BrowsableAttribute(true); // Return properties in sort order. for (int i = 0; i < _objectProperties.Count; i++) { PropertyDescriptor prop = _objectProperties[i]; if (prop.Attributes.Contains(browsable)) { pdc.Add(prop); } } } else { // Return child list shape. PropertyDescriptorCollection itemProps = System.Windows.Forms.ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType); PropertyDescriptorCollection props = new PropertyDescriptorCollection(null); for (int i = 0; i < itemProps.Count; i++) { props.Add(new ObjectView.ObjectViewPropertyDescriptor(itemProps[i])); } pdc = props; } return pdc; }
private PropertyDescriptorCollection GetBrowsableProperties(Type t) { Attribute [] att = new System.Attribute [1]; att [0] = new BrowsableAttribute (true); return TypeDescriptor.GetProperties (t, att); }