通过变量名获取和修改变量
object p;//实例化的类
string var_name;//变量名字
object value;//变量修改值
using System.Reflection;
namespace Assets.变量测试
{
class Set_class_value
{
public static void class_value_set(object p,string var_name,object value)
{
p.GetType().GetField(var_name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(p, value);
}
public static object class_value_get(object p, string var_name)
{
return p.GetType().GetField(var_name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(p);
}
}
}