Exemplo n.º 1
0
    static void FillLuaInvokerGenericArguments(MethodDefinition prototypeMethod, bool bIgnoreReturnValue, bool bAppendCoroutineState, ref MethodReference invoker)
    {
        if (invoker.HasGenericParameters)
        {
            GenericInstanceMethod genericInjectMethod = new GenericInstanceMethod(invoker.CloneMethod());

            if (prototypeMethod.HasThis)
            {
                genericInjectMethod.GenericArguments.Add(prototypeMethod.DeclaringType);
            }
            foreach (ParameterDefinition parameter in prototypeMethod.Parameters)
            {
                var paramType = parameter.ParameterType.IsByReference ? ElementType.For(parameter.ParameterType) : parameter.ParameterType;
                genericInjectMethod.GenericArguments.Add(paramType);
            }
            if (bAppendCoroutineState)
            {
                genericInjectMethod.GenericArguments.Add(intTypeRef);
            }
            if (prototypeMethod.GotPassedByReferenceParam())
            {
                genericInjectMethod.GenericArguments.Add(luaTableTypeDef);
            }
            else if (!bIgnoreReturnValue && !prototypeMethod.ReturnVoid())
            {
                genericInjectMethod.GenericArguments.Add(prototypeMethod.ReturnType);
            }

            invoker = genericInjectMethod;
        }
    }
Exemplo n.º 2
0
    public static MethodReference MakeGenericMethod(this MethodReference self, params TypeReference[] arguments)
    {
        if (self.DeclaringType.IsGenericTypeDefinition())
        {
            return(self.CloneMethod(self.DeclaringType.MakeGenericType(arguments)));
        }
        else
        {
            var genericInstanceMethod = new GenericInstanceMethod(self.CloneMethod());

            foreach (var argument in arguments)
            {
                genericInstanceMethod.GenericArguments.Add(argument);
            }

            return(genericInstanceMethod);
        }
    }