I want to eliminate the type testing in the following code snippet.
Does anyone have any idea how I can do this?
public override T Value {
get {
// I want to use late binding here so that the following call is made:
// bOK = _FolderParmT(ref _value, strFParamVal));
// Let the compiler figure out at runtime which func to call based T's type.
// Until I do that I'll have to parse the type.
// Be sure to update the constructor if you add a new type
T TVal = _value;
if (_value is string) {
string v = null;
bOK = _FolderParmT(ref v, strFParamVal);
if (bOK) TVal = ((T)((object)(v)));
} else if (_value is System.String[]) {
string[] v = null;
bOK = _FolderParmT(ref v, strFParamVal);
if (bOK) TVal = ((T)((object)(v)));
} else if (_value is double) {
double v = double.MinValue;
bOK = _FolderParmT(ref v, strFParamVal);
if (bOK) TVal = ((T)((object)(v)));
} else if (_value is int) {
int v = int.MinValue;
bOK = _FolderParmT(ref v, strFParamVal);
if (bOK) TVal = ((T)((object)(v)));
} else if (_value is long) {
long v = long.MinValue;
bOK = _FolderParmT(ref v, strFParamVal);
if (bOK) TVal = ((T)((object)(v)));
} else if (_value is bool) {
bool v = false;
bOK = _FolderParmT(ref v, strFParamVal);
if (bOK) TVal = ((T)((object)(v)));
}
if (bOK) {
base.SendMessage("\"" + _strFolderParameter + "\" setting: \"" + strFParamVal +"\" was used");
return TVal;
}