[英]Using reflection, how do I detect properties that have setters?
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
( documentation ) PropertyInfo.CanWrite
( 文档 )
or 要么
PropertyInfo.GetSetMethod
( documentation ) PropertyInfo.GetSetMethod
( 文档 )
propertyInfo.GetSetMethod() != null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.