示例#1
0
        public bool MethodMatches(MethodInfo method, bool addToImplementations = true)
        {
            if ((method.GetMethodName() != Name) && (method.Name != Name))
            {
                return(false);
            }
            var declaringType = method.DeclaringType;

            if (BaseType.IsSubclassOf(declaringType))
            {
                return(false);
            }
            if (method.DeclaringType != BaseType)
            {
                return(false);
            }

            if (ReturnType != method.ReturnType)
            {
                return(false);
            }
            var arguments = method.GetParameters().Select(par => par.ParameterType).ToArray();

            if (arguments.Length != Parameters.Length)
            {
                return(false);
            }

            for (var index = 0; index < arguments.Length; index++)
            {
                var argument  = arguments[index];
                var parameter = Parameters[index];
                if (argument != parameter)
                {
                    return(false);
                }
            }
            if (addToImplementations)
            {
//                //Also add all subclasses that use this method
//                foreach (var argument in declaringType)
//                {
//
//                }
                var allInterfaceImplementors = declaringType.Assembly.GetTypes()
                                               .Where(p => declaringType.IsAssignableFrom(p));

                foreach (var allInterfaceImplementor in allInterfaceImplementors)
                {
                    UsingImplementations.Add(allInterfaceImplementor);
                }
                UsingImplementations.Add(declaringType);
            }
            return(true);
        }
示例#2
0
        public bool MethodMatches(MethodInfo method, bool addToImplementations = true)
        {
            if (method.Name != Name)
            {
                return(false);
            }
            var declaringType = method.DeclaringType;

            if (BaseType.IsSubclassOf(declaringType))
            {
                return(false);
            }

            if (ReturnType != method.ReturnType)
            {
                return(false);
            }
            var arguments = method.GetParameters().Select(par => par.ParameterType).ToArray();

            if (arguments.Length != Parameters.Length)
            {
                return(false);
            }

            for (var index = 0; index < arguments.Length; index++)
            {
                var argument  = arguments[index];
                var parameter = Parameters[index];
                if (argument != parameter)
                {
                    return(false);
                }
            }
            if (addToImplementations)
            {
                UsingImplementations.Add(declaringType);
            }
            return(true);
        }