mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-18 13:57:43 +01:00
Add conversion extension method from source enum
This commit is contained in:
parent
8bb6cdd8d6
commit
dd94d10722
1 changed files with 13 additions and 1 deletions
|
|
@ -136,12 +136,24 @@ public class EnumCloneGenerator : IIncrementalGenerator
|
||||||
|
|
||||||
var nsPrefix = targetNamespace is null ? string.Empty : $"namespace {targetNamespace};" + NewLine + NewLine;
|
var nsPrefix = targetNamespace is null ? string.Empty : $"namespace {targetNamespace};" + NewLine + NewLine;
|
||||||
|
|
||||||
|
var sourceFullyQualified = sourceNamed.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||||
|
|
||||||
var code = "// <auto-generated/>" + NewLine + NewLine
|
var code = "// <auto-generated/>" + NewLine + NewLine
|
||||||
+ nsPrefix
|
+ nsPrefix
|
||||||
+ $"public enum {targetName} : {underlyingDisplay}" + NewLine
|
+ $"public enum {targetName} : {underlyingDisplay}" + NewLine
|
||||||
+ "{" + NewLine
|
+ "{" + NewLine
|
||||||
+ membersText + 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";
|
var hintName = $"{targetName}.CloneEnum.g.cs";
|
||||||
spc.AddSource(hintName, SourceText.From(code, Encoding.UTF8));
|
spc.AddSource(hintName, SourceText.From(code, Encoding.UTF8));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue