Example #1
0
        bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
        {
            DefaultParameter p = other as DefaultParameter;

            return(p != null && type == p.type && attributes == p.attributes &&
                   defaultValue == p.defaultValue && region == p.region && flags == p.flags);
        }
Example #2
0
        internal SpecializedParameterizedMember(IType declaringType, IParameterizedMember memberDefinition, TypeVisitor substitution, ITypeResolveContext context)
            : base(declaringType, memberDefinition, substitution, context)
        {
            var paramDefs = memberDefinition.Parameters;

            if (paramDefs.Count == 0)
            {
                this.parameters = EmptyList <IParameter> .Instance;
            }
            else
            {
                var parameters = new IParameter[paramDefs.Count];
                for (int i = 0; i < parameters.Length; i++)
                {
                    ITypeReference newType = Substitute(paramDefs[i].Type, substitution, context);
                    if (newType != paramDefs[i].Type)
                    {
                        parameters[i] = new DefaultParameter(paramDefs[i])
                        {
                            Type = newType
                        };
                    }
                    else
                    {
                        parameters[i] = paramDefs[i];
                    }
                }
                this.parameters = Array.AsReadOnly(parameters);
            }
        }
Example #3
0
        protected IList <IParameter> CreateParameters(TypeVisitor substitution)
        {
            var paramDefs = ((IParameterizedMember)this.baseMember).Parameters;

            if (paramDefs.Count == 0)
            {
                return(EmptyList <IParameter> .Instance);
            }
            else
            {
                var parameters = new IParameter[paramDefs.Count];
                for (int i = 0; i < parameters.Length; i++)
                {
                    var   p       = paramDefs[i];
                    IType newType = p.Type.AcceptVisitor(substitution);
                    parameters[i] = new DefaultParameter(
                        newType, p.Name, this,
                        p.Region, p.Attributes, p.IsRef, p.IsOut,
                        p.IsParams, p.IsOptional, p.ConstantValue,
                        isIn: p.IsIn
                        );
                }
                return(Array.AsReadOnly(parameters));
            }
        }
Example #4
0
		/// <summary>
		/// Performs type substitution in parameter types and in the return type.
		/// </summary>
		public void SubstituteTypes(Func<ITypeReference, ITypeReference> substitution)
		{
			this.ReturnType = substitution(this.ReturnType);
			var p = this.Parameters;
			for (int i = 0; i < p.Count; i++) {
				ITypeReference newType = substitution(p[i].Type);
				if (newType != p[i].Type) {
					p[i] = new DefaultParameter(p[i]) { Type = newType };
				}
			}
		}
		/// <summary>
		/// Performs type substitution in parameter types and in the return type.
		/// </summary>
		public void SubstituteTypes(ITypeResolveContext context, TypeVisitor substitution)
		{
			this.ReturnType = this.ReturnType.Resolve(context).AcceptVisitor(substitution);
			var p = this.Parameters;
			for (int i = 0; i < p.Count; i++) {
				IType newType = p[i].Type.Resolve(context).AcceptVisitor(substitution);
				if (newType != p[i].Type) {
					p[i] = new DefaultParameter(p[i]) { Type = newType };
				}
			}
		}
        /// <summary>
        /// Performs type substitution in parameter types and in the return type.
        /// </summary>
        public void SubstituteTypes(Func <ITypeReference, ITypeReference> substitution)
        {
            this.ReturnType = substitution(this.ReturnType);
            var p = this.Parameters;

            for (int i = 0; i < p.Count; i++)
            {
                ITypeReference newType = substitution(p[i].Type);
                if (newType != p[i].Type)
                {
                    p[i] = new DefaultParameter(p[i])
                    {
                        Type = newType
                    };
                }
            }
        }
Example #7
0
        /// <summary>
        /// Performs type substitution in parameter types and in the return type.
        /// </summary>
        public void SubstituteTypes(ITypeResolveContext context, TypeVisitor substitution)
        {
            this.ReturnType = this.ReturnType.Resolve(context).AcceptVisitor(substitution);
            var p = this.Parameters;

            for (int i = 0; i < p.Count; i++)
            {
                IType newType = p[i].Type.Resolve(context).AcceptVisitor(substitution);
                if (newType != p[i].Type)
                {
                    p[i] = new DefaultParameter(p[i])
                    {
                        Type = newType
                    };
                }
            }
        }
        /// <summary>
        /// Performs type substitution in parameter types and in the return type.
        /// </summary>
        public void SubstituteTypes(Func <ITypeReference, ITypeReference> substitution)
        {
            this.ReturnType = substitution(this.ReturnType);
            var p = this.Parameters;

            for (int i = 0; i < p.Count; i++)
            {
                ITypeReference newType = substitution(p[i].Type);
                if (newType != p[i].Type)
                {
                    p[i] = new DefaultParameter(p[i])
                    {
                        Type = newType
                    };
                }
            }
            // TODO: we might also have to perform substitution within the method's constraints
        }
			public MockImplicitLambda(IType[] expectedParameterTypes, IType inferredReturnType)
			{
				this.expectedParameterTypes = expectedParameterTypes;
				this.inferredReturnType = inferredReturnType;
				this.parameters = new IParameter[expectedParameterTypes.Length];
				for (int i = 0; i < parameters.Length; i++) {
					// UnknownType because this lambda is implicitly typed
					parameters[i] = new DefaultParameter(SpecialType.UnknownType, "X" + i);
				}
			}
Example #10
0
		protected IList<IParameter> CreateParameters(TypeVisitor substitution)
		{
			var paramDefs = ((IParameterizedMember)this.baseMember).Parameters;
			if (paramDefs.Count == 0) {
				return EmptyList<IParameter>.Instance;
			} else {
				var parameters = new IParameter[paramDefs.Count];
				for (int i = 0; i < parameters.Length; i++) {
					var p = paramDefs[i];
					IType newType = p.Type.AcceptVisitor(substitution);
					parameters[i] = new DefaultParameter(
						newType, p.Name, this,
						p.Region, p.Attributes, p.IsRef, p.IsOut,
						p.IsParams, p.IsOptional, p.ConstantValue
					);
				}
				return Array.AsReadOnly(parameters);
			}
		}
 public override string ToString()
 {
     return(DefaultParameter.ToString(this));
 }
Example #12
0
		public IParameter ReadParameter(ParameterDefinition parameter, IParameterizedMember parentMember = null)
		{
			if (parameter == null)
				throw new ArgumentNullException("parameter");
			var type = ReadTypeReference(parameter.ParameterType, typeAttributes: parameter, entity: parentMember);
			DefaultParameter p = new DefaultParameter(type, parameter.Name);
			
			if (parameter.ParameterType is Mono.Cecil.ByReferenceType) {
				if (!parameter.IsIn && parameter.IsOut)
					p.IsOut = true;
				else
					p.IsRef = true;
			}
			AddAttributes(parameter, p);
			
			if (parameter.IsOptional) {
				p.DefaultValue = ReadConstantValue(new CustomAttributeArgument(parameter.ParameterType, parameter.Constant));
			}
			
			if (parameter.ParameterType is Mono.Cecil.ArrayType) {
				foreach (CustomAttribute att in parameter.CustomAttributes) {
					if (att.AttributeType.FullName == typeof(ParamArrayAttribute).FullName) {
						p.IsParams = true;
						break;
					}
				}
			}
			
			return p;
		}
Example #13
0
		void AddAttributes(ParameterDefinition parameter, DefaultParameter targetParameter)
		{
			if (!targetParameter.IsOut) {
				if (parameter.IsIn)
					targetParameter.Attributes.Add(inAttribute);
				if (parameter.IsOut)
					targetParameter.Attributes.Add(outAttribute);
			}
			if (parameter.HasCustomAttributes) {
				AddCustomAttributes(parameter.CustomAttributes, targetParameter.Attributes);
			}
		}
Example #14
0
 void AddAttributes(ParameterDefinition parameter, DefaultParameter targetParameter)
 {
     if (parameter.HasCustomAttributes) {
         AddCustomAttributes(parameter.CustomAttributes, targetParameter.Attributes);
     }
 }
Example #15
0
		internal SpecializedParameterizedMember(IType declaringType, IParameterizedMember memberDefinition, TypeVisitor substitution, ITypeResolveContext context)
			: base(declaringType, memberDefinition, substitution, context)
		{
			var paramDefs = memberDefinition.Parameters;
			if (paramDefs.Count == 0) {
				this.parameters = EmptyList<IParameter>.Instance;
			} else {
				var parameters = new IParameter[paramDefs.Count];
				for (int i = 0; i < parameters.Length; i++) {
					ITypeReference newType = Substitute(paramDefs[i].Type, substitution, context);
					if (newType != paramDefs[i].Type) {
						parameters[i] = new DefaultParameter(paramDefs[i]) { Type = newType };
					} else {
						parameters[i] = paramDefs[i];
					}
				}
				this.parameters = Array.AsReadOnly(parameters);
			}
		}