string className;
Type t=Type.GetType(className);
Type t = Type.GetType(windowName);
ConstructorInfo[] cMethods = t.GetConstructors();
for (int i = 0; i < cMethods.Length; i++)
{
ConstructorInfo ci = cMethods[i];
ParameterInfo[] paramInfos = ci.GetParameters();
Debug.Log("该构造方法名:" + ci.Name + ", 参数个数:" + paramInfos.Length);
if (paramInfos.Length == 3)
{
target = ci.Invoke(new object[] { uiObj, windowName, false }) as Window;
break;
}
}
Type t = Type.GetType(className);
target = Activator.CreateInstance(t, new object[] { uiObj, windowName }) as Window;
dll处理
byte[] buffer = File.ReadAllBytes(path);
var assembly = Assembly.Load(buffer);
foreach (var t in assembly.GetTypes())
{
if (t.IsClass && t.BaseType != null && t.BaseType.Name == typeof(Window).Name)
{
}
}
需求
根据对象中某个字段的字符串名称,来改变该对象某个字段的值
public class Bean
{
public string Name { get; set; }
public int Age { get; set; }
public string Address;
}
var b = new Bean();
b.Name = "zcfly";
b.Age = 12;
b.Address = "China";
Debug.LogError("name1:" + b.Name + ", age1:" + b.Age + ",address1:" + b.Address);
var bType = b.GetType();
var nameP = bType.GetProperty("Name");
nameP.SetValue(b, "Jim", null);
var ageP = bType.GetProperty("Age");
ageP.SetValue(b, 333, null);
var addressM = bType.GetField("Address");
addressM.SetValue(b, "England");
Debug.LogError("name2:" + b.Name + ",age2:" + b.Age + ",address2:" + b.Address);