c# - PropertyInfo.SetValue ArgumentException? -
c# - PropertyInfo.SetValue ArgumentException? -
i have next code. however, has runtime exception on setvalue
. may cause error?
var _filter = new filter(....); // filter implemented ifilter applyfilter(_view.name, x => x.name); private void applyfilter<t>(t curr, expression<func<ifilter, t>> prev) { var expr = (memberexpression)prev.body; var prop = (propertyinfo)expr.member; if (!equalitycomparer<t>.default.equals(curr, (t)_filter[prop.name])) { prop.setvalue(_filter, curr, null); // error ..... // on _filter
the exception is:
system.argumentexception unhandled message=property set method not found. source=mscorlib stacktrace: @ system.reflection.runtimepropertyinfo.setvalue(object obj, object value, bindingflags invokeattr, binder binder, object[] index, cultureinfo culture) @ system.reflection.runtimepropertyinfo.setvalue(object obj, object value, object[] index) @ myapp.errorlogpresenter.applyfilter[t](t curr, expression`1 prev) in d:\....cs:line 50 message=property set method not found.
this means property using does not define setter. either ensure suitable setter exists, or utilize different approach assign values.
c# reflection
Comments
Post a Comment