Rob*_*Rob 1 c# reflection static properties bindingflags
我想知道当我使用GetProperties()提取特定类的所有属性时是否可以排除静态属性。我知道为此使用BindingFlags来过滤我需要的属性,但我真正想要的是我要排除静态属性。我尝试使用这样的东西:
typeof(<class>).GetProperties(!BindingFlags.Static);
Run Code Online (Sandbox Code Playgroud)
但我认为它不起作用,因为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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
对于这种情况,我想在调用GetProperties()时排除“ DataCtrl”属性。感谢您的回复。:)
我认为您正在寻找BindingFlags.Instance | BindingFlags.Public(如果仅包括Instance,则由于Public未NonPublic指定也未找到任何属性)。