I have a generic method SampleMethod(param1, param2) and I need to call the method based on the config value. For example:
SampleMethod<long>(param1, param2);
SampleMethod<Guid>(param1, param2);
On the method call, type should change on the config value. I need to get the value from config file like app.config file.
public static Type RangeType
{
get
{
Type rangeType;
string rangeDataTypeString = ConfigurationManager.AppSettings["ShardRangeType"];
switch (rangeDataTypeString.ToUpper())
{
case "LONG":
rangeType = typeof (long);
break;
case "GUID":
rangeType = typeof (Guid);
break;
default:
rangeType = typeof (long);
break;
}
return rangeType;
}
}
When I try to call this based the configuration value and pass in this value to the above method like:
Type rangeType = Configuration.RangeType;
SampleMethod<rangeType>(param1, param2);
The rangeType in the above statement does not recognize as type, could someone suggest how to accomplish this. Thanks in advance!