Skip to content

Commit

Permalink
Don't use C# keywords in the name of generated converters.
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenGroot committed Jul 14, 2023
1 parent 29006dc commit 2c3918b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Ookii.CommandLine.Generator/CommandGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void Generate()
var source = GenerateManager(manager);
if (source != null)
{
_context.AddSource(manager.ToQualifiedName().ToIdentifier(".g.cs"), SourceText.From(source, Encoding.UTF8));
_context.AddSource(manager.ToDisplayString().ToIdentifier(".g.cs"), SourceText.From(source, Encoding.UTF8));
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/Ookii.CommandLine.Generator/ConverterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ConverterGenerator(TypeHelper typeHelper, SourceProductionContext context
return null;
}

info.Name = GenerateName(type.ToDisplayString());
info.Name = GenerateName(type);
_converters.Add(type, info);
converter = info;
}
Expand Down Expand Up @@ -170,8 +170,15 @@ public ConverterGenerator(TypeHelper typeHelper, SourceProductionContext context
return info;
}

private static string GenerateName(string displayName)
private static string GenerateName(ITypeSymbol type)
{
// Use the full framework name even for types that have keywords, and don't include global
// namespace.
var format = SymbolDisplayFormat.FullyQualifiedFormat
.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted)
.RemoveMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

var displayName = type.ToDisplayString(format);
return displayName.ToIdentifier(ConverterSuffix);
}

Expand Down

0 comments on commit 2c3918b

Please sign in to comment.