gpt4 book ai didi

c# - 使用 GetProperties 方法时如何排除静态属性

转载 作者:太空宇宙 更新时间:2023-11-03 18:37:16 24 4
gpt4 key购买 nike

我想知道当我使用 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”属性。感谢您的回复。 :)

最佳答案

我认为您正在寻找 BindingFlags.Instance | BindingFlags.Public(如果您只包含 Instance,则不会找到任何属性,因为既未指定 Public 也未指定 NonPublic)。

关于c# - 使用 GetProperties 方法时如何排除静态属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13522132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com