Share via


The Custom Attribute Matching Rule

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Unity Application Block information can be found at the Unity Application Block site.

The Custom Attribute Matching Rule allows developers, operators, and administrators to select target classes based on a custom attribute type that is applied to class members.

Behavior of the Custom Attribute Matching Rule

In more detail, the Custom Attribute Matching Rule does the following:

  • It reads the value of the AttributeType and the inherited parameters from the Unity Application Block configuration.
  • It compares the AttributeType value to the type of any attributes that are applied to members of the target object.
  • It searches for matching attribute types in all base classes that the target class inherits from if the inherited parameter is True.
  • It returns True if the attribute type matches the value of the AttributeType parameter; if the attribute type does not match the value of the AttributeType, it returns False.

Configuration Using Constructor Injection for Custom Attribute Matching Rule

Unity uses constructor injection to generate new instances of matching rules. For information about constructor injection, see the following topics:

The following constructor can be used for the CustomAttributeMatchingRule class.

public CustomAttributeMatchingRule(
Type attributeType,
bool inherited
)

The constructor parameters make the following configuration settings available for the Custom Attribute Matching Rule:

  • AttributeType (Type). This is the type name of the custom attribute that is applied to members of the target object, such as "MyCustomAttribute".
  • inherited (Boolean). This specifies whether the rule should also search base classes for members that carry the custom attribute.