Exemple #1
0
    public static void SetPrivateField(this object obj, string name, object value)
    {
        BindingFlags flags     = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
        Type         type      = obj.GetType();
        FieldInfo    fieldInfo = PublicExtensions.GetFieldInfo(type, name, flags);

        if (fieldInfo != null)
        {
            if (fieldInfo.FieldType == typeof(int))
            {
                int num = Convert.ToInt32(value);
                fieldInfo.SetValue(obj, num);
                return;
            }
            if (fieldInfo.FieldType == typeof(float))
            {
                float num2 = Convert.ToSingle(value);
                fieldInfo.SetValue(obj, num2);
                return;
            }
            if (fieldInfo.FieldType == typeof(long))
            {
                long num3 = Convert.ToInt64(value);
                fieldInfo.SetValue(obj, num3);
                return;
            }
            fieldInfo.SetValue(obj, value);
        }
    }
    public static void SetStaticPublicField(string typeName, string name, object value)
    {
        BindingFlags flags     = BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy;
        Type         type      = Type.GetType(typeName);
        FieldInfo    fieldInfo = PublicExtensions.GetFieldInfo(type, name, flags);

        if (fieldInfo != null)
        {
            if (fieldInfo.FieldType == typeof(int))
            {
                int num = Convert.ToInt32(value);
                fieldInfo.SetValue(null, num);
                return;
            }
            if (fieldInfo.FieldType == typeof(float))
            {
                float num2 = Convert.ToSingle(value);
                fieldInfo.SetValue(null, num2);
                return;
            }
            if (fieldInfo.FieldType == typeof(long))
            {
                long num3 = Convert.ToInt64(value);
                fieldInfo.SetValue(null, num3);
                return;
            }
            fieldInfo.SetValue(null, value);
        }
    }
    public static void SetStaticPublicProperty(string typeName, string name, object value)
    {
        BindingFlags flags        = BindingFlags.Static | BindingFlags.Public;
        Type         type         = Type.GetType(typeName);
        PropertyInfo propertyInfo = PublicExtensions.GetPropertyInfo(type, name, flags);

        if (propertyInfo != null)
        {
            if (propertyInfo.PropertyType == typeof(int))
            {
                int num = Convert.ToInt32(value);
                propertyInfo.SetValue(null, num, null);
                return;
            }
            if (propertyInfo.PropertyType == typeof(float))
            {
                float num2 = Convert.ToSingle(value);
                propertyInfo.SetValue(null, num2, null);
                return;
            }
            if (propertyInfo.PropertyType == typeof(long))
            {
                long num3 = Convert.ToInt64(value);
                propertyInfo.SetValue(null, num3, null);
                return;
            }
            propertyInfo.SetValue(null, value, null);
        }
    }
    public static void SetPublicProperty(this object obj, string name, object value)
    {
        BindingFlags flags        = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
        Type         type         = obj.GetType();
        PropertyInfo propertyInfo = PublicExtensions.GetPropertyInfo(type, name, flags);

        if (propertyInfo != null)
        {
            if (propertyInfo.PropertyType == typeof(int))
            {
                int num = Convert.ToInt32(value);
                propertyInfo.SetValue(obj, num, null);
                return;
            }
            if (propertyInfo.PropertyType == typeof(float))
            {
                float num2 = Convert.ToSingle(value);
                propertyInfo.SetValue(obj, num2, null);
                return;
            }
            if (propertyInfo.PropertyType == typeof(long))
            {
                long num3 = Convert.ToInt64(value);
                propertyInfo.SetValue(obj, num3, null);
                return;
            }
            propertyInfo.SetValue(obj, value, null);
        }
    }
Exemple #5
0
    static int GetStaticPublicField(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        string arg0 = LuaScriptMgr.GetLuaString(L, 1);
        string arg1 = LuaScriptMgr.GetLuaString(L, 2);
        object o    = PublicExtensions.GetStaticPublicField(arg0, arg1);

        LuaScriptMgr.PushVarObject(L, o);
        return(1);
    }
Exemple #6
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);
    }
Exemple #7
0
    private static int SetStaticPublicProperty(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        string luaString  = LuaScriptMgr.GetLuaString(L, 1);
        string luaString2 = LuaScriptMgr.GetLuaString(L, 2);
        object varObject  = LuaScriptMgr.GetVarObject(L, 3);

        PublicExtensions.SetStaticPublicProperty(luaString, luaString2, varObject);
        return(0);
    }
Exemple #8
0
    static int SetStaticPublicProperty(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        string arg0 = LuaScriptMgr.GetLuaString(L, 1);
        string arg1 = LuaScriptMgr.GetLuaString(L, 2);
        object arg2 = LuaScriptMgr.GetVarObject(L, 3);

        PublicExtensions.SetStaticPublicProperty(arg0, arg1, arg2);
        return(0);
    }
Exemple #9
0
    private static int GetStaticPublicField(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        string luaString         = LuaScriptMgr.GetLuaString(L, 1);
        string luaString2        = LuaScriptMgr.GetLuaString(L, 2);
        object staticPublicField = PublicExtensions.GetStaticPublicField(luaString, luaString2);

        LuaScriptMgr.PushVarObject(L, staticPublicField);
        return(1);
    }
Exemple #10
0
    static int GetPropertyInfo(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        Type   arg0 = LuaScriptMgr.GetTypeObject(L, 1);
        string arg1 = LuaScriptMgr.GetLuaString(L, 2);

        System.Reflection.BindingFlags arg2 = (System.Reflection.BindingFlags)LuaScriptMgr.GetNetObject(L, 3, typeof(System.Reflection.BindingFlags));
        System.Reflection.PropertyInfo o    = PublicExtensions.GetPropertyInfo(arg0, arg1, arg2);
        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
Exemple #11
0
    private static int GetPropertyInfo(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        Type         typeObject   = LuaScriptMgr.GetTypeObject(L, 1);
        string       luaString    = LuaScriptMgr.GetLuaString(L, 2);
        BindingFlags flags        = (BindingFlags)((int)LuaScriptMgr.GetNetObject(L, 3, typeof(BindingFlags)));
        PropertyInfo propertyInfo = PublicExtensions.GetPropertyInfo(typeObject, luaString, flags);

        LuaScriptMgr.PushObject(L, propertyInfo);
        return(1);
    }
Exemple #12
0
    private static int CallStaticPublicMethod(IntPtr L)
    {
        int    num        = LuaDLL.lua_gettop(L);
        string luaString  = LuaScriptMgr.GetLuaString(L, 1);
        string luaString2 = LuaScriptMgr.GetLuaString(L, 2);

        object[] paramsObject = LuaScriptMgr.GetParamsObject(L, 3, num - 2);
        object   o            = PublicExtensions.CallStaticPublicMethod(luaString, luaString2, paramsObject);

        LuaScriptMgr.PushVarObject(L, o);
        return(1);
    }
Exemple #13
0
    public static T GetPrivatePropertyGeneric <T>(this object obj, string name)
    {
        BindingFlags flags        = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
        Type         type         = obj.GetType();
        PropertyInfo propertyInfo = PublicExtensions.GetPropertyInfo(type, name, flags);

        if (propertyInfo != null)
        {
            return((T)((object)propertyInfo.GetGetMethod(true).Invoke(obj, null)));
        }
        return(default(T));
    }
Exemple #14
0
    public static T GetPrivateFieldGeneric <T>(this object obj, string name)
    {
        BindingFlags flags     = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
        Type         type      = obj.GetType();
        FieldInfo    fieldInfo = PublicExtensions.GetFieldInfo(type, name, flags);

        if (fieldInfo != null)
        {
            return((T)((object)fieldInfo.GetValue(obj)));
        }
        return(default(T));
    }
    public static object GetPublicField(this object obj, string name)
    {
        BindingFlags flags     = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
        Type         type      = obj.GetType();
        FieldInfo    fieldInfo = PublicExtensions.GetFieldInfo(type, name, flags);

        if (fieldInfo != null)
        {
            return(fieldInfo.GetValue(obj));
        }
        return(null);
    }
    public static object GetStaticPublicProperty(string typeName, string name)
    {
        BindingFlags flags        = BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy;
        Type         type         = Type.GetType(typeName);
        PropertyInfo propertyInfo = PublicExtensions.GetPropertyInfo(type, name, flags);

        if (propertyInfo != null)
        {
            return(propertyInfo.GetValue(null, null));
        }
        return(null);
    }
    public static object GetPublicProperty(this object obj, string name)
    {
        BindingFlags flags        = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
        Type         type         = obj.GetType();
        PropertyInfo propertyInfo = PublicExtensions.GetPropertyInfo(type, name, flags);

        if (propertyInfo != null)
        {
            return(propertyInfo.GetGetMethod(false).Invoke(obj, null));
        }
        return(null);
    }
    public static object GetStaticPublicField(string typeName, string name)
    {
        BindingFlags flags     = BindingFlags.Static | BindingFlags.Public;
        Type         type      = Type.GetType(typeName);
        FieldInfo    fieldInfo = PublicExtensions.GetFieldInfo(type, name, flags);

        if (fieldInfo != null)
        {
            return(fieldInfo.GetValue(null));
        }
        return(null);
    }
Exemple #19
0
    static int CallStaticPublicMethod(IntPtr L)
    {
        int    count = LuaDLL.lua_gettop(L);
        string arg0  = LuaScriptMgr.GetLuaString(L, 1);
        string arg1  = LuaScriptMgr.GetLuaString(L, 2);

        object[] objs2 = LuaScriptMgr.GetParamsObject(L, 3, count - 2);
        object   o     = PublicExtensions.CallStaticPublicMethod(arg0, arg1, objs2);

        LuaScriptMgr.PushVarObject(L, o);
        return(1);
    }
    public static PropertyInfo GetPropertyInfo(Type type, string name, BindingFlags flags)
    {
        if (type == null)
        {
            return(null);
        }
        PropertyInfo property = type.GetProperty(name, flags);

        if (property == null && type.BaseType != null)
        {
            return(PublicExtensions.GetPropertyInfo(type.BaseType, name, flags));
        }
        return(property);
    }
    public static FieldInfo GetFieldInfo(Type type, string name, BindingFlags flags)
    {
        if (type == null)
        {
            return(null);
        }
        FieldInfo field = type.GetField(name, flags);

        if (field == null && type.BaseType != null)
        {
            return(PublicExtensions.GetFieldInfo(type.BaseType, name, flags));
        }
        return(field);
    }
Exemple #22
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));
    }
    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)));
    }