Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Shared/LanguageParser/CSharptokenEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ internal override bool FindNextToken()
"is", "lock", "long", "namespace", "new",
"object", "operator", "out", "override", "params",
"private", "protected", "public", "readonly",
"record",
"ref", "return", "sbyte", "sealed", "short",
"sizeof", "stackalloc", "static", "string",
"struct", "switch", "this", "throw", "try",
Expand Down
12 changes: 12 additions & 0 deletions src/Tasks.UnitTests/CSharpParserUtilitites_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ public void Regress_Mutation_SingleLineCommentsShouldBeIgnored(string fileConten
AssertParse(fileContents, "n2.c");
}

[Theory]
[InlineData("namespace MyNamespace { record MyRecord(string Name); }", "MyNamespace.MyRecord")]
[InlineData("namespace MyNamespace; record MyRecord(string Name);", "MyNamespace.MyRecord")]
[InlineData("record MyRecord(string Name);", "MyRecord")]
[InlineData("namespace MyNamespace { public sealed record MyRecord { } }", "MyNamespace.MyRecord")]
[InlineData("namespace MyNamespace { public record class MyRecord { } }", "MyNamespace.MyRecord")]
[InlineData("namespace MyNamespace { record MyRecord(string Name); public static class Extensions { } }", "MyNamespace.MyRecord")]
public void RecordTypeResolution(string fileContents, string expected)
{
AssertParse(fileContents, expected);
}

/*
* Method: AssertParse
*
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/CSharpParserUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static ExtractedClassName Extract(CSharpTokenizer tokens)
result.IsInsideConditionalBlock = true;
}
}
else if (t.InnerText == "class")
else if (t.InnerText == "class" || t.InnerText == "record")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm I am a bit concerned what happens when people use record struct and record class, how is this tokenized in roslyn? 🤔 . But this PR improves on the current state where we don't recognize records at all...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end, also "enum", "structs" and interfaces are not recognized when it comes to resource name generation. Not sure if this method is the right place to find the type name regarding all possible types or if it will break other code.

{
state.ResolvingClass = true;
if (state.InsideConditionalDirective)
Expand Down