Beispiel #1
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);
            }));
        }
Beispiel #2
0
        protected internal override IList <StaticGenericParameterWrapper> GetTypeGenericParameters(StaticDeclaredTypeWrapper type)
        {
            TypeDefinition typeHandle = (TypeDefinition)type.Handle;

            return(CollectionUtils.ConvertAllToArray <GenericParameter, StaticGenericParameterWrapper>(typeHandle.GenericParameters, delegate(GenericParameter parameterHandle)
            {
                return StaticGenericParameterWrapper.CreateGenericTypeParameter(this, parameterHandle, type);
            }));
        }
Beispiel #3
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));
            }
        }
        /// <summary>
        /// Applies a type substitution to the specified generic parameter.
        /// </summary>
        /// <param name="type">The generic parameter to substitute.</param>
        /// <returns>The substituted type.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="type"/> is null.</exception>
        public ITypeInfo Apply(StaticGenericParameterWrapper type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            ITypeInfo replacement;

            if (replacements.TryGetValue(type, out replacement))
            {
                return(replacement);
            }

            return(type);
        }
        /// <summary>
        /// Returns a new substitution with the specified generic parameters replaced by their respective generic arguments.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The extended type substitution is normalized so that generic parameters that
        /// are idempotently replaced with themselves are excluded from the substitution altogether.
        /// </para>
        /// </remarks>
        /// <param name="genericParameters">The generic parameters.</param>
        /// <param name="genericArguments">The generic arguments.</param>
        /// <returns>The resulting substitution.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="genericParameters"/> or <paramref name="genericArguments"/> is null
        /// or contain nulls.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="genericArguments"/> does not have the same
        /// number of elements as <paramref name="genericParameters"/>.</exception>
        public StaticTypeSubstitution Extend(IList <StaticGenericParameterWrapper> genericParameters, IList <ITypeInfo> genericArguments)
        {
            if (genericParameters == null)
            {
                throw new ArgumentNullException("genericParameters");
            }
            if (genericArguments == null)
            {
                throw new ArgumentNullException("genericArguments");
            }

            int count = genericParameters.Count;

            if (genericArguments.Count != count)
            {
                throw new ArgumentException("The generic argument count does not equal the generic parameter count.", "genericArguments");
            }

            if (count == 0)
            {
                return(this);
            }

            var newReplacements = new Dictionary <StaticGenericParameterWrapper, ITypeInfo>(replacements);

            for (int i = 0; i < count; i++)
            {
                StaticGenericParameterWrapper genericParameter = genericParameters[i];
                if (genericParameter == null)
                {
                    throw new ArgumentNullException("genericParameters", "The generic parameters list should not contain null values.");
                }

                ITypeInfo genericArgument = genericArguments[i];
                if (genericArgument == null)
                {
                    throw new ArgumentNullException("genericArguments", "The generic arguments list should not contain null values.");
                }

                if (!genericParameter.Equals(genericArgument))
                {
                    newReplacements[genericParameter] = genericArgument;
                }
            }

            return(new StaticTypeSubstitution(newReplacements));
        }
        protected override int GetGenericParameterPosition(StaticGenericParameterWrapper genericParameter)
        {
            ITypeParameter genericParameterHandle = (ITypeParameter)genericParameter.Handle;
            int parameterIndex = genericParameterHandle.Index;

            // Must also factor in generic parameters of declaring types.
            for (ITypeElement declaringType = genericParameterHandle.OwnerType; declaringType != null; )
            {
                declaringType = declaringType.GetContainingType();
                if (declaringType == null)
                    break;

                parameterIndex += declaringType.TypeParameters.Length;
            }

            return parameterIndex;
        }
        protected override GenericParameterAttributes GetGenericParameterAttributes(StaticGenericParameterWrapper genericParameter)
        {
            ITypeParameter genericParameterHandle = (ITypeParameter)genericParameter.Handle;

            GenericParameterAttributes flags = 0;
            ReflectorFlagsUtils.AddFlagIfTrue(ref flags, GenericParameterAttributes.NotNullableValueTypeConstraint, genericParameterHandle.IsValueType);
            ReflectorFlagsUtils.AddFlagIfTrue(ref flags, GenericParameterAttributes.ReferenceTypeConstraint, genericParameterHandle.IsClassType);
            ReflectorFlagsUtils.AddFlagIfTrue(ref flags, GenericParameterAttributes.DefaultConstructorConstraint, genericParameterHandle.HasDefaultConstructor);
            return flags;
        }
Beispiel #8
0
 /// <summary>
 /// Gets the generic parameter constraints.
 /// </summary>
 /// <param name="genericParameter">The generic parameter, not null.</param>
 /// <returns>The generic parameter constraints.</returns>
 protected internal abstract IList <StaticTypeWrapper> GetGenericParameterConstraints(StaticGenericParameterWrapper genericParameter);
Beispiel #9
0
 /// <summary>
 /// Gets the generic parameter position.
 /// </summary>
 /// <param name="genericParameter">The generic parameter, not null.</param>
 /// <returns>The generic parameter position.</returns>
 protected internal abstract int GetGenericParameterPosition(StaticGenericParameterWrapper genericParameter);
Beispiel #10
0
 /// <summary>
 /// Gets the attributes of a generic parameter.
 /// </summary>
 /// <param name="genericParameter">The generic parameter, not null.</param>
 /// <returns>The generic parameter attributes.</returns>
 protected internal abstract GenericParameterAttributes GetGenericParameterAttributes(StaticGenericParameterWrapper genericParameter);
 protected internal override IList<StaticTypeWrapper> GetGenericParameterConstraints(StaticGenericParameterWrapper genericParameter)
 {
     GenericParameter parameterHandle = (GenericParameter)genericParameter.Handle;
     return CollectionUtils.ConvertAllToArray<TypeReference, StaticTypeWrapper>(parameterHandle.Constraints, MakeType);
 }
 /// <summary>
 /// Gets the generic parameter constraints.
 /// </summary>
 /// <param name="genericParameter">The generic parameter, not null.</param>
 /// <returns>The generic parameter constraints.</returns>
 protected internal abstract IList<StaticTypeWrapper> GetGenericParameterConstraints(StaticGenericParameterWrapper genericParameter);
Beispiel #13
0
        protected internal override GenericParameterAttributes GetGenericParameterAttributes(StaticGenericParameterWrapper genericParameter)
        {
            GenericParameter parameterHandle = (GenericParameter)genericParameter.Handle;

            return((GenericParameterAttributes)parameterHandle.Attributes);
        }
 protected internal override int GetGenericParameterPosition(StaticGenericParameterWrapper genericParameter)
 {
     GenericParameter parameterHandle = (GenericParameter)genericParameter.Handle;
     return parameterHandle.Position;
 }
 protected override IList<StaticTypeWrapper> GetGenericParameterConstraints(StaticGenericParameterWrapper genericParameter)
 {
     ITypeParameter genericParameterHandle = (ITypeParameter)genericParameter.Handle;
     return GenericCollectionUtils.ConvertAllToArray<IType, StaticTypeWrapper>(genericParameterHandle.TypeConstraints, MakeType);
 }
Beispiel #16
0
        protected internal override int GetGenericParameterPosition(StaticGenericParameterWrapper genericParameter)
        {
            GenericParameter parameterHandle = (GenericParameter)genericParameter.Handle;

            return(parameterHandle.Position);
        }
 /// <summary>
 /// Gets the attributes of a generic parameter.
 /// </summary>
 /// <param name="genericParameter">The generic parameter, not null.</param>
 /// <returns>The generic parameter attributes.</returns>
 protected internal abstract GenericParameterAttributes GetGenericParameterAttributes(StaticGenericParameterWrapper genericParameter);
Beispiel #18
0
        protected internal override IList <StaticTypeWrapper> GetGenericParameterConstraints(StaticGenericParameterWrapper genericParameter)
        {
            GenericParameter parameterHandle = (GenericParameter)genericParameter.Handle;

            return(CollectionUtils.ConvertAllToArray <TypeReference, StaticTypeWrapper>(parameterHandle.Constraints, MakeType));
        }
 /// <summary>
 /// Gets the generic parameter position.
 /// </summary>
 /// <param name="genericParameter">The generic parameter, not null.</param>
 /// <returns>The generic parameter position.</returns>
 protected internal abstract int GetGenericParameterPosition(StaticGenericParameterWrapper genericParameter);
 protected internal override GenericParameterAttributes GetGenericParameterAttributes(StaticGenericParameterWrapper genericParameter)
 {
     GenericParameter parameterHandle = (GenericParameter)genericParameter.Handle;
     return (GenericParameterAttributes)parameterHandle.Attributes;
 }