我想知道当我使用 GetProperties() 提取特定类的所有属性时是否可以排除静态属性。我知道为此使用 BindingFlags 来过滤我需要的属性,但我真正想要的是我想排除静态属性。我尝试使用这样的东西:
typeof(<class>).GetProperties(!BindingFlags.Static);
但我认为它不起作用,因为 VS 给我带来了一些语法错误。这是我的类里面的属性。
public class HospitalUploadDtl : Base.Tables
{
public HospitalUploadDtl() { }
public HospitalUploadDtl(SqlDataReader reader)
{
ReadReader(reader);
}
#region Properties
public long BatchDtlId { get; set; }
public long BatchNumber { get; set; }
public string HospitalCode { get; set; }
public string HospitalName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string ContractPerson { get; set; }
public string ContactNo { get; set; }
public string Email { get; set; }
public bool isAccredited { get; set; }
public bool isClinic { get; set; }
public string FaxNo { get; set; }
public string TypeofFacility { get; set; }
public string Category { get; set; }
public string Specialty { get; set; }
public string ProviderName { get; set; }
public bool CashlessInPatient { get; set; }
public bool CashlessOutPatient { get; set; }
#endregion
public static dcHospitalUploadDtl dataCtrl;
public static dcHospitalUploadDtl DataCtrl
{
get
{
if (dataCtrl == null)
dataCtrl = new dcHospitalUploadDtl();
return dataCtrl;
}
}
}
对于这种情况,我想在调用 GetProperties() 时排除“DataCtrl”属性。感谢您的回复。:)