Working with <Nullable>enable</Nullable>
, how can I fix KO
method to allow expression1
as parameter?
public class X
{
public DateTime? dummy {get; }
}
public static class G
{
// Why this doesn't solve the issue? -- \
// |
// v
public static void KO<T>(Expression<Func<X,T?>> p) {}
}
[Fact]
public void Test1()
{
Expression<Func<X,DateTime?>> expression1 = x => x.dummy;
G.KO<DateTime>(expression1);
// error CS1503: Argument 1: cannot convert from
// 'System.Linq.Expressions.Expression<System.Func<gengen.UnitTest1.X, System.DateTime?>>' to
// 'System.Linq.Expressions.Expression<System.Func<gengen.UnitTest1.X, System.DateTime>>'
}
I know some solutions are using !
(for example on EF). But Expression<Func<X,DateTime>> expression1 = x => x.dummy!
also doesn't work for me