Problem with Reflection.FieldInfo.SetValue method
I'm trying to set the value of a property using the Reflection.FieldInfo.SetValue method.
I need to perform a cast on the basis of the field I'm passing the object in to - for example, the JobNumber field requires a string value, so we have to cast the object variable to a string.
This differs with every property we set; therefore if we're setting DeliveryQuantity we'll want to cast to Integer, if we're setting JobNumber we'll want to cast to String, if we're setting DeliveryDate we'll want to cast to Date, etc.
I don't want to have a massive 'Select Case' statement where we work out what property we're setting then do the CType(x,y); at least, not unless there is no other way round at all.
The SetValue(Object,Object,BindingFlags,Binder,Culture Info) method looks like it might do what I need, but the .Net documentation might as well be greek for all the sense I can make of it. Is there anyone who does understand this method, and can explain it to me?
Thanks very much
|