icsharpcode/ILSpy — Issue #282: (T)(object)DateTime.Now; decompiles as (T)DateTime.Now;, which does not compile
Author: martinording
Created: 2011-10-17 20:26:45+00:00
State: open

The long version:

```C#
protected static T? ReadDBNullable(object o) where T : struct
{
if (o == DBNull.Value)
return null;
else if (typeof(DateTime).IsAssignableFrom(typeof(T)))
return (T)(object)DateTime.SpecifyKind((DateTime)o, DateTimeKind.Utc);
else
return (T)o;
}
```

gets decompiled as

```C#
protected static T? ReadDBNullable(object o) where T : struct
{
if (o == DBNull.Value)
{
return null;
}
if (typeof(DateTime).IsAssignableFrom(typeof(T)))
{
return new T?((T)DateTime.SpecifyKind((DateTime)o, DateTimeKind.Utc));
}
return new T?((T)o);
}
```
which does not compile. .Net 4, full.