I realize this question sounds stupid, but please bear with me. I have a class like this:
public class DropDownListViewModel<TScalar>
{
private bool _valueIsSet;
private TScalar _value;
private SelectList _selectList;
public SelectList SelectList
{
get
{
return _selectList;
}
set
{
_selectList = value;
if (_valueIsSet)
{
_selectList.SetSelected(_value);
}
}
}
}
I find using
_valueIsSet
clumsy and would much prefer a
Nullable<TScalar>
where
Nullable
simply "does nothing" if
TScalar
is already nullable.
Basically, I want a generic generic type, e.g:
private MagicVoodooType<TScalar> _value;
Where :
1. When
TScalar
is nullable, e.g. string, then
_value
will have type
TScalar
.
2. When
TScalar
is not nullable, e.g. int, then
_value
will have type
Nullable<TScalar>
.
I know this is a long shot, but I have been through discussions of this before, on another board, and some commenters gave me the impression it might be possible with some magic, i.e. IL level stuff, but seeing as the .NET framework has advanced a lot since my first encounter with this requirement, I was wondering if it might be easier now.