mgravell / fast-member

Automatically exported from code.google.com/p/fast-member
Apache License 2.0
1.02k stars 137 forks source link

C# Named Tuples #72

Closed NickLarsen closed 5 years ago

NickLarsen commented 5 years ago
IEnumerable<(int Id, byte[] Values)> data = new[]
{
    (Id: 1, Values: new byte[1]),
    (Id: 2, Values: new byte[2]),
};
var table = new DataTable();
using (var reader = ObjectReader.Create(data, "Id", "Values"))
{
    table.Load(reader);
}

// throws ArgumentOutOfRangeException: 
// "Specified argument was out of the range of valid values.Parameter name: name"

Was trying to do some quick and dirty data transfer and ran into this. I fixed it by writing a wrapper class but it would have been nice not to have to do that. It looks like the underlying implementation it's picking up is that of a plain old tuple and it finds properties for Item1 and Item2 by default if you don't specify the names when creating the ObjectReader.

mgravell commented 5 years ago

Cannot be solved. Value-tuples only expose names outward, never inward. So: callers can see the names, but callees cannot. Library code is always a callee, so never gets names from value-tuples.

There is no current API or language feature that I can use to avoid this.

On Tue, 12 Mar 2019, 18:11 Nicholas Larsen, notifications@github.com wrote:

IEnumerable<(int Id, byte[] Values)> data = new[] { (Id: 1, Values: new byte[1]), (Id: 2, Values: new byte[2]), }; var table = new DataTable(); using (var reader = ObjectReader.Create(data, "Id", "Values")) { table.Load(reader); }

// throws ArgumentOutOfRangeException: // "Specified argument was out of the range of valid values.Parameter name: name"

Was trying to do some quick and dirty data transfer and ran into this. I fixed it by writing a wrapper class but it would have been nice not to have to do that. It looks like the underlying implementation it's picking up is that of a plain old tuple and it finds properties for Item1 and Item2 by default if you don't specify the names when creating the ObjectReader.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mgravell/fast-member/issues/72, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsCGKIp45xUHFYoUx06fBWqn427ULks5vV-3mgaJpZM4brjy1 .