Add conversion extension method from source enum

This commit is contained in:
goaaats 2026-01-10 17:09:51 +01:00
parent 8bb6cdd8d6
commit dd94d10722

View file

@ -136,12 +136,24 @@ public class EnumCloneGenerator : IIncrementalGenerator
var nsPrefix = targetNamespace is null ? string.Empty : $"namespace {targetNamespace};" + NewLine + NewLine;
var sourceFullyQualified = sourceNamed.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var code = "// <auto-generated/>" + NewLine + NewLine
+ nsPrefix
+ $"public enum {targetName} : {underlyingDisplay}" + NewLine
+ "{" + NewLine
+ membersText + NewLine
+ "}" + NewLine;
+ "}" + NewLine + NewLine;
var extClassName = targetName + "Conversions";
var extMethodName = "ToDalamud" + targetName;
var extClass = $"public static class {extClassName}" + NewLine
+ "{" + NewLine
+ $" public static {targetName} {extMethodName}(this {sourceFullyQualified} value) => ({targetName})(({underlyingDisplay})value);" + NewLine
+ "}" + NewLine;
code += extClass;
var hintName = $"{targetName}.CloneEnum.g.cs";
spc.AddSource(hintName, SourceText.From(code, Encoding.UTF8));