Share via


Excluding By Custom Attribute

Types, methods, and fields may be selectively excluded by custom attribute. A custom attribute rule selects an item (type, method, or field) based on matching against the names of custom attributes that annotate the item. One or more custom attribute rules may be nested inside any rule that selects types, methods, or fields.

A type, method, or field rule may have multiple custom attribute rules associated with it. In this case, an item is selected if at least one of the custom attribute rules selects it.

The following example selects all types that are annotated with either MyCustomAttribute or MyOtherCustomAttribute:

<type name=".*" excludetype="false" regex="true>
   <customattribute name="MyCustomAttribute"/>
...<customattribute name="MyOtherCustomAttribute"/>
</type>

Custom attribute rules can also be written using regular expressions to match custom attribute names. The following example is another way to select all types annotated with either MyCustomAttribute or MyOtherCustomAttribute:

<type name=".*" excludetype="false" regex="true>
   <customattribute name="My.*CustomAttribute" regex="true"/>
</type>

The next example shows how to exclude all methods annotated with a custom attribute named MyCustomAttribute:

<type name=".*" excludetype="false" regex="true">
   <method name=".*" regex="true">
      <customattribute name="MyCustomAttribute"/>
   </method>
</type>

© 2002-2007 PreEmptive Solutions. All rights reserved.