Ejemplo n.º 1
0
 /// <summary>
 /// Construct a new <see cref="ReturnTypeMatchingRule"/> that matches
 /// members with the given return type.
 /// </summary>
 /// <param name="returnType">Type to look for.</param>
 public ReturnTypeMatchingRule(Type returnType)
 {
     if (returnType == null)
     {
         throw new ArgumentNullException("returnType");
     }
     typeMatchingRule = new TypeMatchingRule(returnType.FullName);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Check the given member to see if it has any matching parameters.
        /// </summary>
        /// <param name="member">Member to match.</param>
        /// <returns>true if member matches, false if it doesn't.</returns>
        public bool Matches(MethodBase member)
        {
            Unity.Utility.Guard.ArgumentNotNull(member, "member");

            ParameterInfo[] parametersInfo = member.GetParameters();

            foreach (ParameterTypeMatchingInfo matchInfo in matches)
            {
                TypeMatchingRule typeRule =
                    new TypeMatchingRule(matchInfo.Match, matchInfo.IgnoreCase);
                foreach (ParameterInfo paramInfo in parametersInfo)
                {
                    if ((!paramInfo.IsOut && !paramInfo.IsReturn()) &&
                        (matchInfo.Kind == ParameterKind.Input ||
                         matchInfo.Kind == ParameterKind.InputOrOutput))
                    {
                        if (typeRule.Matches(paramInfo.ParameterType))
                        {
                            return(true);
                        }
                    }

                    if (paramInfo.IsOut &&
                        (matchInfo.Kind == ParameterKind.Output ||
                         matchInfo.Kind == ParameterKind.InputOrOutput))
                    {
                        if (typeRule.Matches(paramInfo.ParameterType.GetElementType()))
                        {
                            return(true);
                        }
                    }

                    if (paramInfo.IsReturn() && matchInfo.Kind == ParameterKind.ReturnValue)
                    {
                        if (typeRule.Matches(paramInfo.ParameterType))
                        {
                            return(true);
                        }
                    }
                }
                if (matchInfo.Kind == ParameterKind.ReturnValue)
                {
                    MethodInfo method = member as MethodInfo;
                    if (method != null)
                    {
                        if (typeRule.Matches(method.ReturnType))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Construct a new <see cref="ReturnTypeMatchingRule"/> that matches
 /// the given return type by name.
 /// </summary>
 /// <remarks>See the <see cref="TypeMatchingRule"/> class for details on how
 /// type name matches are done.</remarks>
 /// <param name="returnTypeName">Type name to match.</param>
 /// <param name="ignoreCase">If false, name comparison is case sensitive. If true, comparison
 /// is case insensitive.</param>
 public ReturnTypeMatchingRule(string returnTypeName, bool ignoreCase)
 {
     typeMatchingRule = new TypeMatchingRule(returnTypeName, ignoreCase);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Construct a new <see cref="ReturnTypeMatchingRule"/> that matches
 /// the given return type by name.
 /// </summary>
 /// <remarks>See the <see cref="TypeMatchingRule"/> class for details on how
 /// type name matches are done.</remarks>
 /// <param name="returnTypeName">Type name to match. Name comparisons are case sensitive.</param>
 public ReturnTypeMatchingRule(string returnTypeName)
 {
     typeMatchingRule = new TypeMatchingRule(returnTypeName);
 }