DapperLib / DapperAOT

Build time tools in the flavor of Dapper
Other
357 stars 19 forks source link

feat(typeaccessor): add isnull custom implementation #26

Closed DeagleGross closed 1 year ago

DeagleGross commented 1 year ago

expected implementation:

public override bool IsNull(T obj, int index) => index switch {
    1 or 2 or 6 => false, // non-nullable value-type
    3 => obj.Name is null, // known reference-type
    4 => obj.DateOfBirth is null, // nullable value-type
    5 => obj.Token is null or DBNull, // object : consider null and the special DBNull
    7 => true, // known to be DBNull ... so: can only ever be null or DbNull, so: always null!
    _ => throw...
}
DeagleGross commented 1 year ago

@mgravell the only thing I dont understand how to check is num 7 from your example: I cant think of a scenario, where property can only be null or DBNull. Can you please assist with explanation?

Other cases are covered I think

mgravell commented 1 year ago
public DBNull StupidProperty {get;set;}

Is completely pointless, but can only be null or DBNull. In reality, this is so overwhelmingly stupid that perhaps I'm overthinking and .StupidProperty is null or DBNull is fine (just like object), but ... meh

DeagleGross commented 1 year ago

let me add the check as well for that stupid case

mgravell commented 1 year ago

Nice, thanks