dotnet/roslyn

DebuggerDisplay fails when access properties in records

Ouverte

#48 469 ouverte le 9 oct. 2020

 (2 commentaires) (0 réaction) (0 personne assignée)C# (4 257 forks)batch import
Area-InteractiveBugFeature - Recordshelp wanted

Métriques du dépôt

Stars
 (20 414 étoiles)
Métriques de merge PR
 (Merge moyen 6j 17h) (256 PRs mergées en 30 j)

Description

Version Used:

  • 5.0.100-rc.1.20452.10

Steps to Reproduce:

public class Program
{
    public static void Main()
    {
        var me = new Person("Phil", "Scott");
        var meWithAccessors = new PersonWithAccessors("Phil", "Scott");
        var meWithMethod = new PersonWithMethod("Phil", "Scott");

        Console.WriteLine("Hello World!");
    }

    [DebuggerDisplay("{FirstName} {LastName}")]
    record Person(string FirstName, string LastName);

    [DebuggerDisplay("{get_FirstName()} {get_LastName()}")]
    record PersonWithAccessors(string FirstName, string LastName);

    [DebuggerDisplay("{GetName(), nq}")]
    record PersonWithMethod(string FirstName, string LastName)
    {
        public string GetName() => $"{FirstName} {LastName}";
    }
}

Expected Behavior:

"Phil Scott" to be display for all three. Well, maybe not the one where I'm going directly to get accessors.

Actual Behavior:

Accesssing via the accessors and a method works fine, but receive the error Property, indexer, or event 'Program.Person.FirstName' is not supported by the language; try directly calling accessor methods 'Program.Person.get_FirstName()' or 'Program.Person.set_FirstName(?)' Property, indexer, or event 'Program.Person.LastName' is not supported by the language; try directly calling accessor methods 'Program.Person.get_LastName()' or 'Program.Person.set_LastName(?)' when going directly to the properties.

Guide contributeur