A code example first is essential I think. I’m trying to build a view model that I will use for all properties that need dropdown controls, and this is a start:
public class ListProperty<TListItem, TValue>
{
private readonly string _valuePropertyName = "Id";
private readonly string _textPropertyName = "Name";
public TValue Value { get; set; }
private IEnumerable<TListItem> _list;
public ListProperty(IEnumerable<TListItem> list)
{
_list = list;
}
}
I would like to have an underlying property for Value that is always nullable, so if TValue is a reference type, the underlying type will just be TValue, but when TValue is a value type, the underlying type must be Nullable<TValue>.
MORE: The reason I want this, is to know whether the Value property has been assigned to or not. To do this without my requirement would involve having to type value as Object, which smells bad to me.
The best I can think of is passing three parameters and just pass one or the other: