Posted on: 7/29/2015 8:25:31 AM | Views : 849

I'm using a foreach to go through all the form fields on a web page. Within the foreach I am calling a method that sets an objects properties passing the key and the key value. The method lives in a class file. Most of the properties are of type string but some are decimal or datetime. Given that I am enumerating through the fields I do not know the type for any given loop. This wouldn't be a problem if I were able to use myMethod(string key, var KeyValue) but I am in a class file so I cannot. I tried using myMethod(string key, dynamic keyValue) but either I used it incorrectly or the value was mistakenly determined at runtime as I got the error "cannot convert string "999" to decimal.
My form field names and my object properties share the same name so what are my options when it comes to looking at the form fields name (key), comparing this to the relevant property and casting it's datatype to the relevant one inside the foreac ...

Go to the complete details ...