Skip to content

Named tuples from C# methods do not retain their names #10502

@SeeminglyScience

Description

@SeeminglyScience

Steps to reproduce

$namedTuple = [Range]::new(0, 0).GetOffsetAndLength(0)
$namedTuple.Offset
$namedTuple.Length

Expected behavior

Offset is translated to Item1 and Length is translated to Item2

0
0

Actual behavior

Tuple items must be referred to by their real property names (e.g. Item1 and Item2).

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.3
PSEdition                      Core
GitCommitId                    7.0.0-preview.3
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Notes

Named tuples are implemented in metadata. The method that returns the tuple is annotated with the TupleElementNames attribute. In the example, the method is annotated with this attribute:

[return: TupleElementNames(new string[] { "Offset", "Length" })]
public ValueTuple<int, int> GetOffsetAndLength(int length);

The item names cannot be inferred from the value itself, but PSInvokeMemberBinder could attach PSAliasProperty's to the tuple after invocation.

Currently this probably isn't all that important. In the version of Core included in7.0.0-preview.3, there are only two public API's in the BCL that return named tuples (the other is Enumerable.Zip<,>(IEnumerable<>,IEnumerable<>)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions