/// <summary>
        /// Creates a wrapper for a generic method parameter.
        /// </summary>
        /// <param name="policy">The reflection policy.</param>
        /// <param name="handle">The underlying reflection object.</param>
        /// <param name="declaringMethod">The declaring method, which must be a generic method definition.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="policy"/>, <paramref name="handle"/>
        /// or <paramref name="declaringMethod"/> is null.</exception>
        public static StaticGenericParameterWrapper CreateGenericMethodParameter(StaticReflectionPolicy policy, object handle,
                                                                                 StaticMethodWrapper declaringMethod)
        {
            if (declaringMethod == null)
            {
                throw new ArgumentNullException("declaringMethod");
            }

            return(new StaticGenericParameterWrapper(policy, handle, declaringMethod.DeclaringType, declaringMethod));
        }
예제 #2
0
        private StaticGenericParameterWrapper MakeGenericParameter(GenericParameter parameterHandle)
        {
            TypeReference typeHandle = parameterHandle.Owner as TypeReference;

            if (typeHandle != null)
            {
                StaticDeclaredTypeWrapper declaringType = MakeDeclaredType(typeHandle);
                return(StaticGenericParameterWrapper.CreateGenericTypeParameter(this, parameterHandle, declaringType));
            }
            else
            {
                MethodReference     methodHandle    = (MethodReference)parameterHandle.Owner;
                StaticMethodWrapper declaringMethod = WrapMethod(methodHandle);
                return(StaticGenericParameterWrapper.CreateGenericMethodParameter(this, parameterHandle, declaringMethod));
            }
        }
예제 #3
0
        private StaticMethodWrapper WrapMethod(MethodReference methodRefHandle)
        {
            var declaringType           = MakeDeclaredType(methodRefHandle.DeclaringType);
            var declaringTypeDefnHandle = (TypeDefinition)declaringType.Handle;
            var methodDefnHandle        = FindMatchingMethod(methodRefHandle.GetElementMethod(), declaringTypeDefnHandle.Methods);
            var method = new StaticMethodWrapper(this, methodDefnHandle, declaringType, declaringType, declaringType.Substitution);

            var genericInstance = methodRefHandle as GenericInstanceMethod;

            if (genericInstance != null)
            {
                var genericArguments = CollectionUtils.ConvertAllToArray <TypeReference, ITypeInfo>(genericInstance.GenericArguments, MakeType);
                method = method.MakeGenericMethod(genericArguments);
            }

            return(method);
        }
예제 #4
0
        /// <summary>
        /// Gets the events that this one overrides or hides.
        /// Only includes overrides that appear on class types, not interfaces.
        /// </summary>
        /// <param name="overridesOnly">If true, only returns overrides.</param>
        public IEnumerable <StaticEventWrapper> GetOverridenOrHiddenEvents(bool overridesOnly)
        {
            StaticMethodWrapper discriminator = GetDiscriminatorMethod(this);

            if (overridesOnly && !discriminator.IsOverride)
            {
                yield break;
            }

            string eventName = Name;

            foreach (StaticDeclaredTypeWrapper baseType in DeclaringType.GetAllBaseTypes())
            {
                foreach (StaticEventWrapper other in ReflectionPolicy.GetTypeEvents(baseType, ReflectedType))
                {
                    if (eventName == other.Name)
                    {
                        if (overridesOnly)
                        {
                            StaticMethodWrapper otherDiscriminator = GetDiscriminatorMethod(other);
                            if (otherDiscriminator == null)
                            {
                                yield break;
                            }

                            if (discriminator.HidesMethod(otherDiscriminator))
                            {
                                yield return(other);

                                if (!otherDiscriminator.IsOverride)
                                {
                                    yield break;
                                }
                                break;
                            }
                        }
                        else
                        {
                            yield return(other);
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Returns true if this method hides the specified method.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method assumes that <paramref name="other"/> is defined by
        /// a base type of this method's declaring type.  It determines whether
        /// method hiding has taken place based on the method's name and its signature
        /// (when IsHideBySig is true).
        /// </para>
        /// </remarks>
        /// <param name="other">The other method.</param>
        /// <returns>True if this method hides the other method.</returns>
        public bool HidesMethod(StaticMethodWrapper other)
        {
            if (Name != other.Name)
            {
                return(false);
            }

            if (!IsHideBySig)
            {
                return(true);
            }

            if (GenericArguments.Count != other.GenericArguments.Count)
            {
                return(false);
            }

            if (IsGenericMethod)
            {
                IList <StaticGenericParameterWrapper> genericParameters      = GenericParameters;
                IList <StaticGenericParameterWrapper> otherGenericParameters = other.GenericParameters;

                if (genericParameters.Count != otherGenericParameters.Count)
                {
                    return(false);
                }

                // Note: We perform a substitution on the method parameters to ensure that the
                //       same generic parameter references are used for both.  Any generic method
                //       parameter references that appear in the signature should thus be directly comparable.
                return(CompareSignatures(GenericMethodDefinition,
                                         other.GenericMethodDefinition.MakeGenericMethod(
                                             new CovariantList <StaticGenericParameterWrapper, ITypeInfo>(genericParameters))));
            }

            if (other.IsGenericMethod)
            {
                return(false);
            }

            return(CompareSignatures(this, other));
        }
예제 #6
0
        protected internal override StaticParameterWrapper GetMethodReturnParameter(StaticMethodWrapper method)
        {
            var methodHandle = (MethodDefinition)method.Handle;

            return(new StaticParameterWrapper(this, methodHandle.MethodReturnType, method));
        }
 private StaticGenericParameterWrapper(StaticReflectionPolicy policy, object handle,
                                       StaticDeclaredTypeWrapper declaringType, StaticMethodWrapper declaringMethod)
     : base(policy, handle, declaringType)
 {
     this.declaringMethod = declaringMethod;
 }
예제 #8
0
 /// <summary>
 /// Gets the return parameter of a method.
 /// </summary>
 /// <param name="method">The method, not null.</param>
 /// <returns>The return parameter.</returns>
 protected internal abstract StaticParameterWrapper GetMethodReturnParameter(StaticMethodWrapper method);
예제 #9
0
 /// <summary>
 /// Gets the generic parameters of a method.
 /// </summary>
 /// <param name="method">The method, not null.</param>
 /// <returns>The generic parameters.</returns>
 protected internal abstract IList <StaticGenericParameterWrapper> GetMethodGenericParameters(StaticMethodWrapper method);
 protected internal override IList<StaticGenericParameterWrapper> GetMethodGenericParameters(StaticMethodWrapper method)
 {
     MethodDefinition methodHandle = (MethodDefinition)method.Handle;
     return CollectionUtils.ConvertAllToArray<GenericParameter, StaticGenericParameterWrapper>(methodHandle.GenericParameters, delegate(GenericParameter parameterHandle)
     {
         return StaticGenericParameterWrapper.CreateGenericMethodParameter(this, parameterHandle, method);
     });
 }
 private StaticGenericParameterWrapper(StaticReflectionPolicy policy, object handle,
     StaticDeclaredTypeWrapper declaringType, StaticMethodWrapper declaringMethod)
     : base(policy, handle, declaringType)
 {
     this.declaringMethod = declaringMethod;
 }
 /// <summary>
 /// Gets the generic parameters of a method.
 /// </summary>
 /// <param name="method">The method, not null.</param>
 /// <returns>The generic parameters.</returns>
 protected internal abstract IList<StaticGenericParameterWrapper> GetMethodGenericParameters(StaticMethodWrapper method);
예제 #13
0
        protected override IList<StaticGenericParameterWrapper> GetMethodGenericParameters(StaticMethodWrapper method)
        {
            IFunction methodHandle = (IFunction)method.Handle;
            if (!methodHandle.IsValid())
                return EmptyArray<StaticGenericParameterWrapper>.Instance;

            ITypeParameter[] parameterHandles = methodHandle.GetSignature(methodHandle.IdSubstitution).GetTypeParameters();

            return Array.ConvertAll<ITypeParameter, StaticGenericParameterWrapper>(parameterHandles, delegate(ITypeParameter parameter)
            {
                return StaticGenericParameterWrapper.CreateGenericMethodParameter(this, parameter, method);
            });
        }
예제 #14
0
        protected override IList<StaticGenericParameterWrapper> GetMethodGenericParameters(StaticMethodWrapper method)
        {
            IFunction methodHandle = (IFunction)method.Handle;
            if (!methodHandle.IsValid())
                return Common.Collections.EmptyArray<StaticGenericParameterWrapper>.Instance;

#if RESHARPER_60_OR_NEWER
            var typeParameters = methodHandle.GetSignature(methodHandle.IdSubstitution).TypeParameters;
            var parameterHandles = new ITypeParameter[typeParameters.Count];
            for (var i = 0; i < parameterHandles.Length; i++)
            {
                parameterHandles[i] = typeParameters[i];
            }
#else
            ITypeParameter[] parameterHandles = methodHandle.GetSignature(methodHandle.IdSubstitution).GetTypeParameters();
#endif

            return Array.ConvertAll(parameterHandles, parameter => 
				StaticGenericParameterWrapper.CreateGenericMethodParameter(this, parameter, method));
        }
예제 #15
0
        /// <summary>
        /// Returns true if this method hides the specified method.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method assumes that <paramref name="other"/> is defined by
        /// a base type of this method's declaring type.  It determines whether
        /// method hiding has taken place based on the method's name and its signature
        /// (when IsHideBySig is true).
        /// </para>
        /// </remarks>
        /// <param name="other">The other method.</param>
        /// <returns>True if this method hides the other method.</returns>
        public bool HidesMethod(StaticMethodWrapper other)
        {
            if (Name != other.Name)
                return false;

            if (! IsHideBySig)
                return true;

            if (GenericArguments.Count != other.GenericArguments.Count)
                return false;

            if (IsGenericMethod)
            {
                IList<StaticGenericParameterWrapper> genericParameters = GenericParameters;
                IList<StaticGenericParameterWrapper> otherGenericParameters = other.GenericParameters;

                if (genericParameters.Count != otherGenericParameters.Count)
                    return false;

                // Note: We perform a substitution on the method parameters to ensure that the
                //       same generic parameter references are used for both.  Any generic method
                //       parameter references that appear in the signature should thus be directly comparable.
                return CompareSignatures(GenericMethodDefinition,
                    other.GenericMethodDefinition.MakeGenericMethod(
                    new CovariantList<StaticGenericParameterWrapper, ITypeInfo>(genericParameters)));
            }

            if (other.IsGenericMethod)
                return false;

            return CompareSignatures(this, other);
        }
        private StaticMethodWrapper WrapMethod(MethodReference methodRefHandle)
        {
            var declaringType = MakeDeclaredType(methodRefHandle.DeclaringType);
            var declaringTypeDefnHandle = (TypeDefinition)declaringType.Handle;
            var methodDefnHandle = FindMatchingMethod(methodRefHandle.GetElementMethod(), declaringTypeDefnHandle.Methods);
            var method = new StaticMethodWrapper(this, methodDefnHandle, declaringType, declaringType, declaringType.Substitution);

            var genericInstance = methodRefHandle as GenericInstanceMethod;
            if (genericInstance != null)
            {
                var genericArguments = CollectionUtils.ConvertAllToArray<TypeReference, ITypeInfo>(genericInstance.GenericArguments, MakeType);
                method = method.MakeGenericMethod(genericArguments);
            }

            return method;
        }
 protected internal override StaticParameterWrapper GetMethodReturnParameter(StaticMethodWrapper method)
 {
     var methodHandle = (MethodDefinition)method.Handle;
     return new StaticParameterWrapper(this, methodHandle.MethodReturnType, method);
 }
예제 #18
0
        protected override StaticParameterWrapper GetMethodReturnParameter(StaticMethodWrapper method)
        {
            IFunction methodHandle = (IFunction)method.Handle;
            if (!methodHandle.IsValid())
                return null;

            // TODO: This won't provide access to any parameter attributes.  How should we retrieve them?
            IType type = methodHandle.ReturnType;
#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
            if (type == null || ! type.IsValid)
#else
            if (type == null || ! type.IsValid())
#endif
                return null;

#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
            var parameter = new Parameter(methodHandle, type, null);
#else
            var parameter = new Parameter(methodHandle, 0, type, null);
#endif
            return new StaticParameterWrapper(this, parameter, method);
        }
예제 #19
0
        protected internal override IList <StaticGenericParameterWrapper> GetMethodGenericParameters(StaticMethodWrapper method)
        {
            MethodDefinition methodHandle = (MethodDefinition)method.Handle;

            return(CollectionUtils.ConvertAllToArray <GenericParameter, StaticGenericParameterWrapper>(methodHandle.GenericParameters, delegate(GenericParameter parameterHandle)
            {
                return StaticGenericParameterWrapper.CreateGenericMethodParameter(this, parameterHandle, method);
            }));
        }
 /// <summary>
 /// Gets the return parameter of a method.
 /// </summary>
 /// <param name="method">The method, not null.</param>
 /// <returns>The return parameter.</returns>
 protected internal abstract StaticParameterWrapper GetMethodReturnParameter(StaticMethodWrapper method);
        /// <summary>
        /// Creates a wrapper for a generic method parameter.
        /// </summary>
        /// <param name="policy">The reflection policy.</param>
        /// <param name="handle">The underlying reflection object.</param>
        /// <param name="declaringMethod">The declaring method, which must be a generic method definition.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="policy"/>, <paramref name="handle"/>
        /// or <paramref name="declaringMethod"/> is null.</exception>
        public static StaticGenericParameterWrapper CreateGenericMethodParameter(StaticReflectionPolicy policy, object handle,
            StaticMethodWrapper declaringMethod)
        {
            if (declaringMethod == null)
                throw new ArgumentNullException("declaringMethod");

            return new StaticGenericParameterWrapper(policy, handle, declaringMethod.DeclaringType, declaringMethod);
        }