I have a C# method that I would like to use to update some data. The method could be passed either a string, a double, an integer
public void Update(string ac, string pr, string fld, Int32 intVal = null, double dblVal = null, string strVal = null)
{
Depending on the value of fld I would want to update a certain field name in my table.
Is there some way I could code up the function parameters so I would not have to supply a long list of possible value types?
Ideally I would like to be able to call this function like this:
Update("key1", "key2", "location", "London");
Update("key1" , "key2", "beds", 2);
Update("key1" , "key2", "price", 123.45);
Then inside the function update I would like to have:
public void Update(string ac, string pr, xxx, yyy)
{
try
{
vm.Product = _product.Get(ac, pr);
vm.Product.xxx = yyy;
_product.AddOrUpdate(vm.Product);
}
catch (Exception e) { log(e); }
}
In the xxx I would like to give the field name and yyy the actual value. Maybe inside the function I could do some kind of casting with a case method based on the field name. I only have a small number of field names so that could be easy. Also maybe there is a way I could find the datatype from reflection of the vm class but that's far beyond my knowledge.