簡體   English   中英

使用反射,如何檢測具有setter的屬性?

[英]Using reflection, how do I detect properties that have setters?

我有這個代碼循環一個對象,並通過反射獲取其所有屬性:

foreach (var propertyInfo in typeof(TBase).GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
    var oldValue = propertyInfo.GetValue(oldVersion, null);
}

如何檢查只查看有“設置”的屬性? (我想忽略只讀值 - 只是“獲取”。)

PropertyInfo.CanWrite文檔

要么

PropertyInfo.GetSetMethod文檔

propertyInfo.GetSetMethod() != null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM