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)
or
PropertyInfo.GetSetMethod
(documentation)
propertyInfo.GetSetMethod() != null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With