public class Cftea {    
  public string SiteName { get; set; }    
  public string Domain { get; set; }            
  
  public string GetValue(string name)    
  {        
    return Convert.ToString(this.GetType().GetProperty(name).GetValue(this, null));    
  }
}

调用时:

Cftea cftea = new Cftea(); string siteName = cftea.GetValue("SiteName");

有人问,为什么要这么做呢?主要适用于配置型的开发中,比如将要获取的属性的名称字符串写入 XML 文件,再根据 XML 中配置的属性名称字符串来获取值。

相关文章:

  • 2021-06-15
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2021-09-22
相关资源
相似解决方案