Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 5a7f380

Browse files
author
ash.blade
committed
add System.Collections.Generic using to generator
1 parent 4e8f91e commit 5a7f380

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

samples/EnumClass.RawEnumComparison/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ void PrintEnumClassComparison(string representationName, PetKind enumClassKind,
2323

2424
var result = enumClassKind.Switch(2, 2,
2525
static (dog, i, j) => i + j * 2,
26-
// static (cat, i, j) => cat.CalculateValue(i, j),
27-
static (cat, i, j) => 0,
26+
static (cat, i, j) => cat.CalculateValue(i, j),
2827
static (parrot, i, j) => i * j + 1,
2928
static (hamster, i, j) => i + j);
3029
Console.WriteLine($"It says that 2+2 is {result}");

src/EnumClass.Generator/EnumClassIncrementalGenerator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ private static void GenerateAllEnumClasses(Compilation
3030
ImmutableArray<EnumDeclarationSyntax> enums,
3131
SourceProductionContext context)
3232
{
33+
// Do not use EnumInfoFactory that accepts compilation,
34+
// because it will search for all enums in all assemblies
35+
// but we need only enums from this assembly
36+
3337
// Why do i need to compile? Skip!
3438
if (enums.IsDefaultOrEmpty)
3539
{
@@ -56,6 +60,7 @@ private static void GenerateAllEnumClasses(Compilation
5660
builder.Append("#nullable enable\n\n");
5761
}
5862
builder.AppendLine("using System;");
63+
builder.AppendLine("using System.Collections.Generic;");
5964
builder.AppendLine("using System.Runtime.CompilerServices;");
6065
builder.AppendLine();
6166
builder.AppendFormat("namespace {0}\n{{\n", enumInfo.Namespace);

0 commit comments

Comments
 (0)