public static void Equals(EditorBrowsableState state1, EditorBrowsableState state2, bool equal) { var attr1 = new EditorBrowsableAttribute(state1); var attr2 = new EditorBrowsableAttribute(state2); Assert.True(attr1.Equals(attr1)); Assert.Equal(equal, attr1.Equals(attr2)); Assert.Equal(equal, attr2.Equals(attr1)); Assert.Equal(equal, attr1.GetHashCode().Equals(attr2.GetHashCode())); }
public override bool Equals(object obj) { if (obj == this) { return(true); } EditorBrowsableAttribute other = obj as EditorBrowsableAttribute; return((other != null) && other.browsableState == browsableState); }
/// <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>()); }
// ============================================== private bool LookupIsBrowsable() { Object attr = LookupCustomAttribute(typeof(EditorBrowsableAttribute)); if (null != attr) { EditorBrowsableAttribute eba = (EditorBrowsableAttribute)attr; if (eba.State == EditorBrowsableState.Never) { return(false); } } return(true); }
public static void TestEqual() { var attr = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); Assert.Equal(attr, attr); Assert.True(attr.Equals(attr)); Assert.Equal(attr.GetHashCode(), attr.GetHashCode()); Assert.Equal(new EditorBrowsableAttribute(EditorBrowsableState.Advanced), attr); Assert.Equal(new EditorBrowsableAttribute(EditorBrowsableState.Advanced).GetHashCode(), attr.GetHashCode()); Assert.NotEqual(new EditorBrowsableAttribute(EditorBrowsableState.Always), attr); Assert.NotEqual(new EditorBrowsableAttribute(EditorBrowsableState.Never).GetHashCode(), attr.GetHashCode()); Assert.False(attr.Equals(null)); }
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>()); }
// Determine if two instances of this class are equal. public override bool Equals(Object obj) { EditorBrowsableAttribute other = (obj as EditorBrowsableAttribute); if (other != null) { return(state == other.state); } else { return(false); } }
public static void TestEqual() { var attr = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); Assert.Equal(attr, attr); Assert.True(attr.Equals(attr)); Assert.Equal(attr.GetHashCode(), attr.GetHashCode()); Assert.Equal(new EditorBrowsableAttribute(EditorBrowsableState.Advanced), attr); Assert.Equal(new EditorBrowsableAttribute(EditorBrowsableState.Advanced).GetHashCode(), attr.GetHashCode()); Assert.NotEqual(new EditorBrowsableAttribute(EditorBrowsableState.Always), attr); Assert.NotEqual(new EditorBrowsableAttribute(EditorBrowsableState.Never).GetHashCode(), attr.GetHashCode()); Assert.False(attr.Equals(null)); }
static bool IsNotEditorBrowsable(MemberInfo member) { object [] editorBrowsableAttributes = member.GetCustomAttributes( typeof(EditorBrowsableAttribute), false); if (editorBrowsableAttributes.Length == 0) { return(false); } EditorBrowsableAttribute editorBrowsableAttribute = (EditorBrowsableAttribute)editorBrowsableAttributes [0]; return(editorBrowsableAttribute.State == EditorBrowsableState.Never); }
public void TestComponentModel() { WarningException we = new WarningException("a message"); we = new WarningException(null); AreEqual(EditorBrowsableState.Advanced.ToString(), "Advanced"); EditorBrowsableAttribute eba = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); Assert(eba.GetType().IsSubclassOf(typeof(System.Attribute))); #if !SILVERLIGHT //SilverlightProxies.cs does not define the State property AreEqual(eba.State, EditorBrowsableState.Advanced); #endif }
public static void TestPreAppStartClass(Type preAppStartType) { Assert.IsTrue(preAppStartType.IsSealed && preAppStartType.IsAbstract, "The type '{0}' should be static.", preAppStartType.FullName); Assert.IsTrue(preAppStartType.IsPublic, "The type '{0}' should be public.", preAppStartType.FullName); Assert.AreEqual("PreApplicationStartCode", preAppStartType.Name, "The type '{0}' has the wrong name.", preAppStartType.FullName); object[] attrs = preAppStartType.GetCustomAttributes(typeof(EditorBrowsableAttribute), true); Assert.AreEqual(1, attrs.Length, "The type '{0}' should have [EditorBrowsable(EditorBrowsableState.Never)] applied to it.", preAppStartType.FullName); EditorBrowsableAttribute editorAttr = (EditorBrowsableAttribute)attrs[0]; Assert.AreEqual(EditorBrowsableState.Never, editorAttr.State, "The type '{0}' should have [EditorBrowsable(EditorBrowsableState.Never)] applied to it.", preAppStartType.FullName); MemberInfo[] publicMembers = preAppStartType.GetMembers(BindingFlags.Public | BindingFlags.Static); Assert.AreEqual(1, publicMembers.Length, "The type '{0}' should have only one public member.", preAppStartType.FullName); Assert.AreEqual(MemberTypes.Method, publicMembers[0].MemberType, "The only public member on type '{0}' should be a method called Start().", preAppStartType.FullName); Assert.AreEqual("Start", publicMembers[0].Name, "The only public member on type '{0}' should be a method called Start().", preAppStartType.FullName); }
private void AddCalendarAttributes() { AddCallback( typeof(Calendar), delegate(AttributeCallbackBuilder builder) { // Set the default property and event builder.AddCustomAttributes(new DefaultPropertyAttribute("SelectedDate")); builder.AddCustomAttributes(new DefaultEventAttribute("SelectedDatesChanged")); // Add the Calendar properties to a Calendar category CategoryAttribute calendarCategory = new CategoryAttribute("Calendar"); builder.AddCustomAttributes("BlackoutDates", calendarCategory); builder.AddCustomAttributes(Calendar.CalendarButtonStyleProperty, calendarCategory); builder.AddCustomAttributes(Calendar.CalendarDayButtonStyleProperty, calendarCategory); builder.AddCustomAttributes(Calendar.CalendarItemStyleProperty, calendarCategory); builder.AddCustomAttributes(Calendar.DisplayDateEndProperty, calendarCategory); builder.AddCustomAttributes(Calendar.DisplayDateProperty, calendarCategory); builder.AddCustomAttributes(Calendar.DisplayDateStartProperty, calendarCategory); builder.AddCustomAttributes(Calendar.DisplayModeProperty, calendarCategory); builder.AddCustomAttributes(Calendar.FirstDayOfWeekProperty, calendarCategory); builder.AddCustomAttributes(Calendar.IsTodayHighlightedProperty, calendarCategory); builder.AddCustomAttributes(Calendar.SelectedDateProperty, calendarCategory); builder.AddCustomAttributes("SelectedDates", calendarCategory); builder.AddCustomAttributes(Calendar.SelectionModeProperty, calendarCategory); // Put the Style properties in the "Advanced" part of the category EditorBrowsableAttribute advanced = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); builder.AddCustomAttributes(Calendar.CalendarButtonStyleProperty, advanced); builder.AddCustomAttributes(Calendar.CalendarDayButtonStyleProperty, advanced); builder.AddCustomAttributes(Calendar.CalendarItemStyleProperty, advanced); // SelectedDates and BlackoutDates conflict with each other for now hide them both // to avoid the result of setting a property being an error in the designer builder.AddCustomAttributes("BlackoutDates", BrowsableAttribute.No); builder.AddCustomAttributes("SelectedDates", BrowsableAttribute.No); }); }
internal static IEnumerable <SelectListItem> ToSelectListItems <T>() where T : struct { Type enumType = typeof(T); if (!enumType.IsEnum) { throw new InvalidOperationException("T must be an Enum."); } foreach (FieldInfo field in enumType.GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public)) { EditorBrowsableAttribute editorBrowsableAttribute = field.GetCustomAttribute <EditorBrowsableAttribute>(); if (editorBrowsableAttribute == null || editorBrowsableAttribute.State != EditorBrowsableState.Never) { yield return(new SelectListItem() { Value = field.GetValue(null).ToString(), Text = GetEnumDescription(field) }); } } }
private bool IsAdvanced(CategoryEditor editor) { AttributeCollection attributes = null; try { attributes = TypeDescriptor.GetAttributes(editor); } catch (Exception) { } if (attributes != null) { foreach (Attribute attribute in attributes) { EditorBrowsableAttribute browsable = attribute as EditorBrowsableAttribute; if (browsable != null) { return(browsable.State == EditorBrowsableState.Advanced); } } } return(false); }
static ReceiveDesigner() { AttributeTableBuilder builder = new AttributeTableBuilder(); Type receiveType = typeof(Receive); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); var categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(CorrelationsCategoryLabelKey)); var descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingCorrelatesWithHint", "<Correlation handle>")); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelatesWith"), categoryAttribute, descriptionAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelatesOn"), categoryAttribute, BrowsableAttribute.Yes, PropertyValueEditor.CreateEditorAttribute(typeof(CorrelatesOnValueEditor))); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), categoryAttribute, BrowsableAttribute.Yes, PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(MiscellaneousCategoryLabelKey)); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("DisplayName"), categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("OperationName"), categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("ServiceContractName"), categoryAttribute, new TypeConverterAttribute(typeof(XNameConverter))); descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingValueHint", "<Value to bind>")); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Content"), categoryAttribute, descriptionAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(ReceiveContentPropertyEditor))); var advancedAttribute = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Action"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes( receiveType, "KnownTypes", advancedAttribute, categoryAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(TypeCollectionPropertyEditor)), new EditorOptionAttribute { Name = TypeCollectionPropertyEditor.AllowDuplicate, Value = false }); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("ProtectionLevel"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("SerializerOption"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CanCreateInstance"), advancedAttribute, categoryAttribute); Action = receiveType.GetProperty("Action").Name; Type receiveMessageContentType = typeof(ReceiveMessageContent); Message = receiveMessageContentType.GetProperty("Message").Name; DeclaredMessageType = receiveMessageContentType.GetProperty("DeclaredMessageType").Name; MetadataStore.AddAttributeTable(builder.CreateTable()); Func <Activity, IEnumerable <ArgumentAccessor> > argumentAccessorGenerator = (activity) => new ArgumentAccessor[] { new ArgumentAccessor { Getter = (ownerActivity) => { Receive receive = (Receive)ownerActivity; ReceiveMessageContent content = receive.Content as ReceiveMessageContent; return(content != null ? content.Message : null); }, Setter = (ownerActivity, arg) => { Receive receive = (Receive)ownerActivity; ReceiveMessageContent content = receive.Content as ReceiveMessageContent; if (content != null) { content.Message = arg as OutArgument; } }, }, }; ActivityArgumentHelper.RegisterAccessorsGenerator(receiveType, argumentAccessorGenerator); }