Example #1
0
    static int CastNumberParameters(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        object[]      objs0 = LuaScriptMgr.GetArrayObject <object>(L, 1);
        Type[]        objs1 = LuaScriptMgr.GetArrayObject <Type>(L, 2);
        List <Type[]> o     = PublicExtensions.CastNumberParameters(objs0, objs1);

        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
    public static T CallPublicMethodGeneric <T>(this object obj, string name, params object[] param)
    {
        BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
        Type         type        = obj.GetType();

        Type[] array = new Type[param.Length];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = param[i].GetType();
        }
        List <Type[]> list       = PublicExtensions.CastNumberParameters(param, array);
        MethodInfo    methodInfo = null;

        try
        {
            methodInfo = type.GetMethod(name, bindingAttr);
        }
        catch
        {
            for (int j = 0; j < list.Count; j++)
            {
                methodInfo = type.GetMethod(name, list[j]);
                if (methodInfo != null)
                {
                    break;
                }
            }
        }
        if (methodInfo == null)
        {
            return(default(T));
        }
        ParameterInfo[] parameters = methodInfo.GetParameters();
        object[]        array2     = new object[parameters.Length];
        for (int k = 0; k < parameters.Length; k++)
        {
            if (parameters[k].ParameterType != typeof(object))
            {
                array2[k] = Convert.ChangeType(param[k], parameters[k].ParameterType);
            }
            else
            {
                array2[k] = param[k];
            }
        }
        return((T)((object)methodInfo.Invoke(obj, array2)));
    }
Example #3
0
    public static object CallStaticPrivateMethod(string typeName, string name, params object[] param)
    {
        BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
        Type         type        = Type.GetType(typeName);

        Type[] array = new Type[param.Length];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = param[i].GetType();
        }
        List <Type[]> list       = PublicExtensions.CastNumberParameters(param, array);
        MethodInfo    methodInfo = null;

        try
        {
            methodInfo = type.GetMethod(name, bindingAttr);
        }
        catch
        {
            for (int j = 0; j < list.Count; j++)
            {
                methodInfo = type.GetMethod(name, list[j]);
                if (methodInfo != null)
                {
                    break;
                }
            }
        }
        if (methodInfo == null)
        {
            return(null);
        }
        ParameterInfo[] parameters = methodInfo.GetParameters();
        object[]        array2     = new object[parameters.Length];
        for (int k = 0; k < parameters.Length; k++)
        {
            if (parameters[k].ParameterType != typeof(object))
            {
                array2[k] = Convert.ChangeType(param[k], parameters[k].ParameterType);
            }
            else
            {
                array2[k] = param[k];
            }
        }
        return(methodInfo.Invoke(null, array2));
    }