Is there a converter in .NET 4.0 that supports conversions between nullable types to shorten instructions like:
bool? nullableBool = GetSomething();
byte? nb
I would write an extension method:
public static class Extensions
{
public static TDest? ConvertTo(this TSource? source)
where TDest: struct
where TSource: struct
{
if (source == null)
{
return null;
}
return (TDest)Convert.ChangeType(source.Value, typeof(TDest));
}
}
and then:
bool? nullableBool = true;
byte? nbyte = nullableBool.ConvertTo();