Partilhar via


ICommonDynamicVisible Interface

Definition

The ICommonDynamicVisible interface should be implemented by any class that wants to limit the visibility of certain Enum values based on state of the class at that moment.

If a class contains a property which exposes an Enum and that class implements the ICommonDynamicVisible interface then it will be called for each property that is of an Enum type.

The context param can be used to determine for which Enum this method is being called. If a class only has one Enum it is not necessary to make this check.

The way to limit the visibility of certain items is to simply remove the unwanted Enum values from the values ArrayList. This method is called on every drop down of the enum so it is possible to change the list on each and every drop down. If the list will not change once it has been initially determined caching the ArrayList and returning it would be helpful.

Care should be taken to ensure that you are not removing values that the Enum property is already set to. This will not cause any errors as all Enum values are still valid but when the user clicks on the dropdown they will not see the current choice as an option.

Also no new values should be added to the list since these values will not be convertable to valid Enum values and an error will be thrown at runtime. If more dynamic control is needed then consider using the DynamicValues design.

public interface ICommonDynamicVisible
type ICommonDynamicVisible = interface
Public Interface ICommonDynamicVisible

Methods

ConfigureVisibleEnumFields(ITypeDescriptorContext, ArrayList)

Removing items from the values list and returning that new list will control the values shown in the Enum specified in context.

The enum can be determined with code similar to the following if (context.PropertyDescriptor.PropertyType == typeof(myEnum))

Applies to