Repository: dotnet/runtime
File: src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorTests.cs (C#)

Code before:
                using System.Text.Json.Serialization;

                public class Model
                {
                    public string type { get; set; }
                    public string alias { get; set; }
                    public string @class { get; set; }
                    public string @struct { get; set; }
                }

                [JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
                [JsonSerializable(typeof(Model))]
                internal partial class ModelContext : JsonSerializerContext
                {
                }
                """;

            Compilation compilation = CompilationHelper.CreateCompilation(source);
            CompilationHelper.RunJsonSourceGenerator(compilation, logger: logger);
        }

#if ROSLYN4_4_OR_GREATER && NET
        [Fact]
        public void InitOnlyPropertyWithReservedKeywordName_CompilesSuccessfully()
        {
            // Regression test for https://github.com/dotnet/runtime/issues/116507
            // Verbatim identifiers like @else should be correctly handled in property initializers.

            string source = """
                #nullable enable
                using System.Text.Json.Serialization;

                public record A
                {
                    public A? @else { get; init; }
                }

                [JsonSerializable(typeof(A))]
                public partial class MyContext : JsonSerializerContext
                {
                }
                """;

            Compilation compilation = CompilationHelper.CreateCompilation(source);
            CompilationHelper.RunJsonSourceGenerator(compilation, logger: logger);
        }
#endif

        [Fact]
        public void RefStructPropertyWithJsonIgnore_CompilesSuccessfully()
        {

Review comment (suggestion):
The issue number in this comment (116507) doesn't match the issue number mentioned in the PR description (122732). Please verify which issue number is correct and update the comment accordingly.
```suggestion
            // Regression test for https://github.com/dotnet/runtime/issues/122732
```

Code after:
                using System.Text.Json.Serialization;

                public class Model
                {
                    public string type { get; set; }
                    public string alias { get; set; }
                    public string @class { get; set; }
                    public string @struct { get; set; }
                }

                [JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
                [JsonSerializable(typeof(Model))]
                internal partial class ModelContext : JsonSerializerContext
                {
                }
                """;

            Compilation compilation = CompilationHelper.CreateCompilation(source);
            CompilationHelper.RunJsonSourceGenerator(compilation, logger: logger);
        }

        [Fact]
        public void InitOnlyPropertyWithReservedKeywordName_CompilesSuccessfully()
        {
            // Verbatim identifiers like @else should be correctly handled in property initializers.

            string source = """
                using System.Text.Json.Serialization;

                public class MyClass
                {
                    public string @else { get; init; }
                }

                [JsonSerializable(typeof(MyClass))]
                public partial class MyContext : JsonSerializerContext
                {
                }
                """;

            Compilation compilation = CompilationHelper.CreateCompilation(source);
            CompilationHelper.RunJsonSourceGenerator(compilation, logger: logger);
        }

        [Fact]
        public void RefStructPropertyWithJsonIgnore_CompilesSuccessfully()
        {
            // Regression test for https://github.com/dotnet/runtime/issues/98590

            string source = """
                using System;