Mono.CSharp.MethodSpec.MakeGenericMethod C# (CSharp) Method

MakeGenericMethod() public method

public MakeGenericMethod ( IMemberContext context ) : MethodSpec
context IMemberContext
return MethodSpec
        public MethodSpec MakeGenericMethod(IMemberContext context, params TypeSpec[] targs)
        {
            if (targs == null)
                throw new ArgumentNullException ();
            // TODO MemberCache
            //			if (generic_intances != null && generic_intances.TryGetValue (targs, out ginstance))
            //				return ginstance;

            //if (generic_intances == null)
            //    generic_intances = new Dictionary<TypeSpec[], Method> (TypeSpecArrayComparer.Default);

            var inflator = new TypeParameterInflator (context, DeclaringType, GenericDefinition.TypeParameters, targs);

            var inflated = (MethodSpec) MemberwiseClone ();
            inflated.declaringType = inflator.TypeInstance;
            inflated.returnType = inflator.Inflate (returnType);
            inflated.parameters = parameters.Inflate (inflator);
            inflated.targs = targs;
            inflated.constraints = TypeParameterSpec.InflateConstraints (inflator, constraints ?? GenericDefinition.TypeParameters);
            inflated.state |= StateFlags.PendingMakeMethod;

            //			if (inflated.parent == null)
            //				inflated.parent = parent;

            //generic_intances.Add (targs, inflated);
            return inflated;
        }

Usage Example

Example #1
0
File: generic.cs Project: ikvm/mono
		/// <summary>
		///   Type inference.  Try to infer the type arguments from `method',
		///   which is invoked with the arguments `arguments'.  This is used
		///   when resolving an Invocation or a DelegateInvocation and the user
		///   did not explicitly specify type arguments.
		/// </summary>
		public static int InferTypeArguments (ResolveContext ec, Arguments arguments, ref MethodSpec method)
		{
			ATypeInference ti = ATypeInference.CreateInstance (arguments);
			TypeSpec[] i_args = ti.InferMethodArguments (ec, method);
			if (i_args == null)
				return ti.InferenceScore;

			if (i_args.Length == 0)
				return 0;

			method = method.MakeGenericMethod (i_args);
			return 0;
		}