模型类:TestModel

public class TestModel

{

private string _name;

private int _id;

public TestModel()

{}

public string Name

{

get { return _name; }

set { _name = value; }

}

public int Id

{

get { return _id; }

set { _id = value; }

}

}

 

逻辑类:TestGetValue

public class TestGetValue

{

public TestGetValue()

{}

public string GetValue(TestModel tm)

{

return tm.Name + " In TestGetValue ";

}

}

 

页面:TestReflection.aspx.cs

void Rel()

{

 

Type t = typeof(TestModel);

TestModel tm = new TestModel();

t.GetProperty("Name").SetValue(tm, "BackStreetBoy", null);

 

TestGetValue tg = new TestGetValue();

Response.Write(tg.GetValue(tm));

}

 

输出结果:

    BackStreetBoy In TestGetValue

设值成功。窃喜…笔记—利用反射给对象赋值笔记—利用反射给对象赋值

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-02
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-03-10
相关资源
相似解决方案