4
過濾掉受保護的setters我想反映一個類型,並獲得公共setter的屬性。這似乎不適合我。在下面的示例LinqPad腳本中,'Id'和'InternalId'與'Hello'一起返回。我能做些什麼來濾除它們?當type.GetProperties()
void Main()
{
typeof(X).GetProperties(BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance)
.Select (x => x.Name).Dump();
}
public class X
{
public virtual int Id { get; protected set;}
public virtual int InternalId { get; protected internal set;}
public virtual string Hello { get; set;}
}
上次我信任.CanWrite屬性!謝謝! – mcintyre321