我需要從MyClass獲取屬性列表,不包括「只讀」屬性,我可以得到它們嗎?如何從類中獲取「ReadOnly」或「WriteOnly」屬性?
public class MyClass
{
public string Name { get; set; }
public int Tracks { get; set; }
public int Count { get; }
public DateTime SomeDate { set; }
}
public class AnotherClass
{
public void Some()
{
MyClass c = new MyClass();
PropertyInfo[] myProperties = c.GetType().
GetProperties(BindingFlags.Public |
BindingFlags.SetProperty |
BindingFlags.Instance);
// what combination of flags should I use to get 'readonly' (or 'writeonly')
// properties?
}
}
而在去年,coluld我得到「時間排序?我知道添加排序依據<>,但如何?我只是使用擴展。 在此先感謝。
有'PropertyInfo'上的幾個屬性指示讀/寫性 – 2013-03-15 18:13:59
'myProperties.IsReadOnly'屬性PropertyInfo []屬性之一 – MethodMan 2013-03-15 18:15:57