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);
        }
    }
Esempio n. 3
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);
    }
Esempio n. 4
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);
    }
    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);
    }
Esempio n. 7
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));
    }
    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);
    }