npgsql icon indicating copy to clipboard operation
npgsql copied to clipboard

Suggestion: Add `Deconstruct()` for Npgsql types

Open tlewis-ba opened this issue 10 months ago • 11 comments

Background

Deconstruct() is an extension method added (I think) in C# 10.

It lets you access the fields of a struct/object in one go, like this:

        PropertyInfo prop = dateType.GetProperty("Now");
        var (isStatic, isRO, isIndexed, propType) = prop;

Suggestion

If we added Deconstruct() to the Npgsql types, it'd make it easier to access the individual fields, like this:

   var (start, end) = my_npgsql_lseg;

I was looking at this because we often have to do stuff like this in the pl/dotnet unit tests:

double a = orig_line.A;
double b = orig_line.B;
double c = orig_line.C;

Where instead we could be doing this

var (a, b, c) = orig_line;

Can we do it for you?

If we did it today, it'd be on our current, stale fork, and then we'd have to do it again for the latest version. What we might do is upgrade to the latest version and then just do it once.

However, at the moment, we just launched our beta and have a lot of work stemming from that, so while I feel like we could probably do this at some point, it won't be soon.

So, I figured that I would raise the issue here, and if someone else wants to do it now, then great, and if we do it later, than also good.

Happy to discuss.

tlewis-ba avatar Apr 15 '24 21:04 tlewis-ba