The Return Type Matching Rule

Microsoft Enterprise Library 5.0

DropDown image DropDownHover image Collapse image Expand image CollapseAll image ExpandAll image Copy image CopyHover image

The return type matching rule allows developers, operators, and administrators to select target classes based on the type or the type name of the return value, using wildcard characters if required.

Behavior of the Return Type Matching Rule

The return type matching rule does the following:

  • It uses the value of the parameters passed to it to configure the matching rule for injection.
  • It compares the return type value to the type returned by members of the target object.
  • 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 parameter is False.
  • It returns True if the type or type name matches the value of the match string; if the type name does not match the value of the match string, 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 Return Type Matching Rule at Run Time

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

C# Copy Code
ReturnTypeMatchingRule(Type returnType)

ReturnTypeMatchingRule(string returnTypeName)

ReturnTypeMatchingRule(string returnTypeName, bool ignoreCase)
Visual Basic Copy Code
ReturnTypeMatchingRule(returnType As Type)

ReturnTypeMatchingRule(returnTypeName As String)

ReturnTypeMatchingRule(returnTypeName As String, ignoreCase As Boolean)

The following table describes the parameters shown above.




Type. The type of the return value of the method to match.


String. The full namespace-qualified name or just the type name of the type of the return value of the method to match. The following are examples:





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

The following code extract shows how you can add a return type matching rule to a policy using the Unity interception mechanism.

C# Copy Code
                (new InjectionConstructor("MyReturnType", true))
                new ContainerControlledLifetimeManager());
Visual Basic Copy Code
myContainer.Configure(Of Interception)() _
           .AddPolicy("MyPolicy") _
           .AddMatchingRule(Of ReturnTypeMatchingRule) _
                (New InjectionConstructor("MyReturnType", 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.