测试例
[TestFixture]
public class Class1
{
private string name;
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
[Test]
public void Test()
{
Class1 c = new Class1();
object[] objs = new object[1];
objs[0] = "stephen";
MethodInfo[] methods = typeof(Class1).GetMethods();
foreach(MethodInfo m in methods)
{
if(m.Name.StartsWith("set_"))
{
m.Invoke(c, objs);
}
Console.WriteLine(m.Name);
}
Console.WriteLine(c.Name);
}
}
public class Class1
{
private string name;
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
[Test]
public void Test()
{
Class1 c = new Class1();
object[] objs = new object[1];
objs[0] = "stephen";
MethodInfo[] methods = typeof(Class1).GetMethods();
foreach(MethodInfo m in methods)
{
if(m.Name.StartsWith("set_"))
{
m.Invoke(c, objs);
}
Console.WriteLine(m.Name);
}
Console.WriteLine(c.Name);
}
}
输出:
------ Test started: Assembly: Cosmos.SpaceStation.Share.BeanUtils.dll ------
GetHashCode
Equals
ToString
get_Name
set_Name
Test
GetType
stephen
1 passed, 0 failed, 0 skipped, took 0.77 seconds.