使用反射,如何检测具有setter的属性? [英] Using reflection, how do I detect properties that have setters?
本文介绍了使用反射,如何检测具有setter的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码可以遍历一个对象并通过反射获取其所有属性:
I have this code to loop through an object and get all of its properties through reflection:
foreach (var propertyInfo in typeof(TBase).GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
var oldValue = propertyInfo.GetValue(oldVersion, null);
}
如何检查仅查看带有设置"的属性?(我想忽略只读值-只是获取".)
How can I do a check to only look at properties that have a "Set" on them? (I want to ignore read-only values - just "Get".)
推荐答案
PropertyInfo.CanWrite
(或
PropertyInfo.GetSetMethod
(文档)
这篇关于使用反射,如何检测具有setter的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文