Ejemplo n.º 1
0
        private static bool MatchProperty(GenericContext <PropertyDefinition> candidate, GenericContext <PropertyDefinition> property)
        {
            var mCandidate = candidate.Item;
            var mProperty  = property.Item;

            if (mCandidate.Name != mProperty.Name)
            {
                return(false);
            }

            if ((mCandidate.GetMethod ?? mCandidate.SetMethod).HasOverrides)
            {
                return(false);
            }

            if (mCandidate.HasParameters || mProperty.HasParameters)
            {
                if (!mCandidate.HasParameters || !mProperty.HasParameters || mCandidate.Parameters.Count != mProperty.Parameters.Count)
                {
                    return(false);
                }

                for (int index = 0; index < mCandidate.Parameters.Count; index++)
                {
                    if (!MatchParameters(candidate.ApplyTo(mCandidate.Parameters[index]), property.ApplyTo(mProperty.Parameters[index])))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        private static bool MatchMethod(GenericContext <MethodDefinition> candidate, GenericContext <MethodDefinition> method)
        {
            var mCandidate = candidate.Item;
            var mMethod    = method.Item;

            if (mCandidate.Name != mMethod.Name)
            {
                return(false);
            }

            if (mCandidate.HasOverrides)
            {
                return(false);
            }

            if (mCandidate.IsSpecialName != method.Item.IsSpecialName)
            {
                return(false);
            }

            if (mCandidate.HasGenericParameters || mMethod.HasGenericParameters)
            {
                if (!mCandidate.HasGenericParameters || !mMethod.HasGenericParameters || mCandidate.GenericParameters.Count != mMethod.GenericParameters.Count)
                {
                    return(false);
                }
            }

            if (mCandidate.HasParameters || mMethod.HasParameters)
            {
                if (!mCandidate.HasParameters || !mMethod.HasParameters || mCandidate.Parameters.Count != mMethod.Parameters.Count)
                {
                    return(false);
                }

                for (int index = 0; index < mCandidate.Parameters.Count; index++)
                {
                    if (!MatchParameters(candidate.ApplyTo(mCandidate.Parameters[index]), method.ApplyTo(mMethod.Parameters[index])))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static bool MatchInterfaceMethod(MethodDefinition candidate, MethodDefinition method, TypeReference interfaceContextType)
        {
            var candidateContext = CreateGenericContext(candidate.DeclaringType);
            var gCandidate       = candidateContext.ApplyTo(candidate);

            if (interfaceContextType is GenericInstanceType)
            {
                var methodContext = new GenericContext <TypeDefinition>(interfaceContextType.Resolve(), ((GenericInstanceType)interfaceContextType).GenericArguments);
                var gMethod       = methodContext.ApplyTo(method);
                return(MatchMethod(gCandidate, gMethod));
            }
            else
            {
                var methodContext = CreateGenericContext(interfaceContextType.Resolve());
                var gMethod       = candidateContext.ApplyTo(method);
                return(MatchMethod(gCandidate, gMethod));
            }
        }