LuaInterface.CodeGeneration.GetDelegate C# (CSharp) Method

GetDelegate() public method

public GetDelegate ( Type delegateType, LuaFunction luaFunc ) : Delegate
delegateType System.Type
luaFunc LuaFunction
return System.Delegate
        public Delegate GetDelegate(Type delegateType, LuaFunction luaFunc)
        {
            List<Type> returnTypes=new List<Type>();
            Type luaDelegateType;
            if (delegateCollection.ContainsKey(delegateType))
            {
                luaDelegateType=delegateCollection[delegateType];
            }
            else
            {
                luaDelegateType=GenerateDelegate(delegateType);
                delegateCollection[delegateType] = luaDelegateType;
            }
            MethodInfo methodInfo=delegateType.GetMethod("Invoke");
            returnTypes.Add(methodInfo.ReturnType);
            foreach(ParameterInfo paramInfo in methodInfo.GetParameters())
                if(paramInfo.ParameterType.IsByRef)
                    returnTypes.Add(paramInfo.ParameterType);
            LuaDelegate luaDelegate=(LuaDelegate)Activator.CreateInstance(luaDelegateType);
            luaDelegate.function=luaFunc;
            luaDelegate.returnTypes=returnTypes.ToArray();
            return Delegate.CreateDelegate(delegateType,luaDelegate,"CallFunction");
        }