advanced userinterface design
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.UserInterface.Generator
|
||||
{
|
||||
internal static class PanelStateIncrementalGeneratorEmitter
|
||||
{
|
||||
|
||||
public static void Emit(
|
||||
SourceProductionContext context,
|
||||
PanelStateIncrementalGeneratorOutput source
|
||||
)
|
||||
{
|
||||
if (source.TypeAnalyses.IsDefaultOrEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder builder = new();
|
||||
_ = builder.AppendLine("// <auto-generated />");
|
||||
_ = builder.AppendLine("#nullable enable");
|
||||
_ = builder.AppendLine();
|
||||
_ = builder.AppendLine("namespace StgSharp.UserInterface.Generator");
|
||||
_ = builder.AppendLine("{");
|
||||
_ = builder.AppendLine(" internal static class PanelStateIncrementalGeneratorManifest");
|
||||
_ = builder.AppendLine(" {");
|
||||
_ = builder.AppendLine(" /*");
|
||||
_ = builder.AppendLine(" internal static string[] DiscoveredTypes { get; } = new string[]");
|
||||
_ = builder.AppendLine(" {");
|
||||
|
||||
foreach (string typeName in source.TypeAnalyses
|
||||
.Select(static analysis => analysis.Target.TypeDisplayName)
|
||||
.Distinct()
|
||||
.OrderBy(static name => name, StringComparer.Ordinal))
|
||||
{
|
||||
_ = builder.Append(" \"");
|
||||
_ = builder.Append(typeName.Replace("\"", "\"\"", StringComparison.Ordinal));
|
||||
_ = builder.AppendLine("\",");
|
||||
}
|
||||
|
||||
_ = builder.AppendLine(" };");
|
||||
_ = builder.AppendLine();
|
||||
_ = builder.AppendLine(" internal static string[] AnalysisSummary { get; } = new string[]");
|
||||
_ = builder.AppendLine(" {");
|
||||
|
||||
foreach (PanelStateIncrementalGeneratorTypeAnalysis analysis in source.TypeAnalyses
|
||||
.OrderBy(static item => item.Target.TypeDisplayName, StringComparer.Ordinal))
|
||||
{
|
||||
string summary = $"{analysis.Target.TypeDisplayName} | symbols={analysis.StateSymbols.Members.Length} | bindings={analysis.StateChangeBindings.Members.Length} | handlers={analysis.StateChangeCommandHandlers.Members.Length}";
|
||||
_ = builder.Append(" \"");
|
||||
_ = builder.Append(summary.Replace("\"", "\"\"", StringComparison.Ordinal));
|
||||
_ = builder.AppendLine("\",");
|
||||
}
|
||||
|
||||
_ = builder.AppendLine(" };");
|
||||
_ = builder.AppendLine(" }");
|
||||
_ = builder.AppendLine("}");
|
||||
|
||||
context.AddSource(
|
||||
"PanelStateIncrementalGeneratorManifest.g.cs",
|
||||
SourceText.From(builder.ToString(), Encoding.UTF8));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user