다음을 통해 공유


The Member Name Matching Rule

The member name matching rule allows developers, operators, and administrators to select target classes based on the name of the class members (methods or properties), and allows you to use wildcard characters for the member name.

Behavior of the Member Name Matching Rule

The member name matching rule does the following:

  • It uses the value of the parameters passed to it to configure the matching rule for injection.
  • It compares each member name to match to the names of the members of the target object, taking into account any wildcard characters.
  • It performs the comparison on a non-case-sensitive basis if the ignoreCase parameter is True or on a case-sensitive basis if the ignoreCase property is False.
  • It returns True if any of the member name to match values match a target object member name; if none match a target object member name, it returns False.

The matching rules for a policy can be defined in configuration or created and applied to policies at run time. For more information about configuring matching rules at design time, see Configuration Files for Interception in the section Design-Time Configuration.

Creating a Member Name Matching Rule at Run Time

The following constructor overloads can be used when creating an instance of the MemberNameMatchingRule class.

MemberNameMatchingRule(string nameToMatch)

MemberNameMatchingRule(string nameToMatch, bool ignoreCase)

MemberNameMatchingRule(IEnumerable<string> namesToMatch)

MemberNameMatchingRule(IEnumerable<string> namesToMatch, bool ignoreCase)

MemberNameMatchingRule(IEnumerable<MatchingInfo> matches)
'Usage
MemberNameMatchingRule(nameToMatch As String)

MemberNameMatchingRule(nameToMatch As String, ignoreCase As Boolean)

MemberNameMatchingRule(namesToMatch As IEnumerable(Of String))

MemberNameMatchingRule(namesToMatch As IEnumerable(Of String), ignoreCase As Boolean)

MemberNameMatchingRule(matches As IEnumerable(Of MatchingInfo))

The following table describes the parameters shown above.

Parameter

Description

nameToMatch

This is the name of a method or parameter of the target object, such as GetOrderDetails. It can consist of or include the * or ? wildcard characters for selecting multiple types. You can also use square brackets [ ] to specify a range of characters. The following are some examples:

GetOrder*

*OrderFunctions

OrderProcess??Node

Transacted[order]Node

*

namesToMatch

String collection. A list of more than one method or parameter name, using the same rules as for the nameToMatch parameter.

matches

MatchingInfo collection. A list of one or more method or parameter names, using the same rules as for the nameToMatch parameter. MatchingInfo is a class used for storing information about a single name and case-sensitivity value pair.

ignoreCase

Boolean. This specifies whether the match should be carried out on a case-sensitive basis. The default is false.

The following code excerpt shows how you can add a member name matching rule to a policy using the Unity interception mechanism.

myContainer.Configure<Interception>()
           .AddPolicy("MyPolicy")
           .AddMatchingRule<MemberNameMatchingRule>
                (new InjectionConstructor("MyMemberName", true))
           .AddCallHandler<MyCallHandler>
               ("MyValidator", 
               new ContainerControlledLifetimeManager());
'Usage
myContainer.Configure(Of Interception)() _
           .AddPolicy("MyPolicy") _
           .AddMatchingRule(Of MemberNameMatchingRule) _
               (New InjectionConstructor("MyMemberName", True)) _
           .AddCallHandler(Of MyCallHandler) _
               ("MyValidator", New ContainerControlledLifetimeManager())

The code does not show how to create the container, add the Unity interception container extension, specify an interceptor, or resolve the intercepted target object. For more information about using matching rules with interception at run time, see Registering Policy Injection Components.