Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectReader, AllowDBNull and non-nullable reference types #82

Open
AdamWillden opened this issue Mar 3, 2020 · 4 comments
Open

ObjectReader, AllowDBNull and non-nullable reference types #82

AdamWillden opened this issue Mar 3, 2020 · 4 comments

Comments

@AdamWillden
Copy link

AdamWillden commented Mar 3, 2020

Hi,

I'm using ObjectReader to allow me to assert behaviour in tests that use an IDataReader. We're using c#8 with non-nullable reference types.

The detection of nullability does not cater for this: allowNull = !(memberType.IsValueType && memberType == tmp);

See the example model below as to my desired output.

public class A
{
    public string Foo { get; set; } //AllowDBNull expected false, actual true (FAIL)
        = string.Empty;

    public string? Bar { get; set; } //AllowDBNull expected true, actual true (PASS)
        = string.Empty;

    public int Fizz { get; set; } //AllowDBNull expected false, actual false (PASS)
        = int.MaxValue;

    public int? Buzz { get; set; } //AllowDBNull expected true, actual true (PASS)
        = int.MaxValue;
}

Detecting nullability for reference types is a bit of a pain - what are your thoughts around handling this? Desired?


Thank you for efforts creating and maintaining this package, no doubt you don't get enough praise. I've only just become aware of this package and expect to be using it in runtime code very soon. Thank you again and keep up the good work 👍

@mgravell
Copy link
Owner

mgravell commented Mar 3, 2020 via email

@AdamWillden
Copy link
Author

AdamWillden commented Mar 4, 2020

@mgravell no kidding about the nullable attribute mechanism, that in itself is a project to find the most reliable and performant method. I knew this when raising the ticket 😁 If there's anyone up to such a challenge... 😉

I've seen a few sources relating to nullable reference type checks and they're all pretty hideous and by extension (I imagine) not very good in relation to performance.

@brandonryan
Copy link

Just a heads up. NullabilityInfoContext makes this a lot easier and less hideous now.

@mgravell
Copy link
Owner

Dapper AOT now has a build-time object reader implementation. I think it is probably time to simply see whether we can move people to a different code base, designed with the current needs in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants