Look at this method:
Dictionary<string,object> ViewModelParams = new Dictionary<string,object>();
AddParam(string paramKey,value)
{
viewModelParams.Add(paramKey,value);
}
T GetParam<T>(string paramKey)
{
if(viewModelParams[paramKey] is T)
return (T)viewModelParams[paramKey];
else
throw exception...
}
For Nullable types the expression if(viewModelParams[paramKey] is T)
, if value in dictionary was null, not worked properly, to clarify:
int? item=null;
AddParam("key",item);
GetParam<int?>("key")// throw exception because of
// (viewModelParams[paramKey] is T) is false
I know concepts of boxing and unboxing for nullable type(Boxing Nullable Types), but i don't know which expression replaced with if(viewModelParams[paramKey] is T)
for this scenario?