From 83d97aa25cf5897fbd5d9d2b6149357e1eebe425 Mon Sep 17 00:00:00 2001 From: naratteu Date: Thu, 28 May 2026 13:37:33 +0000 Subject: [PATCH 1/2] srcgen-fba --- content/srcgen-fba/Sample.cs | 39 +++++++++++++++++++++++++++++++++ content/srcgen-fba/Test.cs | 12 ++++++++++ content/srcgen-fba/nuget.config | 6 +++++ 3 files changed, 57 insertions(+) create mode 100644 content/srcgen-fba/Sample.cs create mode 100644 content/srcgen-fba/Test.cs create mode 100644 content/srcgen-fba/nuget.config diff --git a/content/srcgen-fba/Sample.cs b/content/srcgen-fba/Sample.cs new file mode 100644 index 0000000..a749c13 --- /dev/null +++ b/content/srcgen-fba/Sample.cs @@ -0,0 +1,39 @@ +#:sdk Naratteu.SourceGenerator.Sdk@0.0.11 + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Text; +using System.Diagnostics.CodeAnalysis; +using System.Text; + +[Generator] +public class SampleGenerator : IIncrementalGenerator +{ + void IIncrementalGenerator.Initialize(IncrementalGeneratorInitializationContext context) + { + context.RegisterPostInitializationOutput(ctx => + { + ctx.AddEmbeddedAttributeDefinition(); + ctx.AddSource("FriendAttribute.g.cs", """ + namespace Sample + { + [Microsoft.CodeAnalysis.Embedded] + public class FriendAttribute : System.Attribute; + } + """); + }); + context.RegisterSourceOutput( + context.SyntaxProvider.ForAttributeWithMetadataName("Sample.FriendAttribute", (_, _) => true, (c, _) => c).Collect(), + (ctx, sources) => + { + ctx.AddSource($"Hello.g.cs", $$""" + namespace Sample + { + public static class Hello + { + public static void World() => System.Console.WriteLine("Hello {{string.Join(", ", sources.Select(s => s.TargetSymbol.Name))}} !"); + } + } + """); + }); + } +} \ No newline at end of file diff --git a/content/srcgen-fba/Test.cs b/content/srcgen-fba/Test.cs new file mode 100644 index 0000000..2d43a7a --- /dev/null +++ b/content/srcgen-fba/Test.cs @@ -0,0 +1,12 @@ +#:package Sample@0.0.1 +using Sample; + +Hello.World(); + +[Friend] class Github; +[Friend] class DotnetDev; + +/* +dotnet pack Sample.cs -p:Version=0.0.1 +dotnet Test.cs +*/ \ No newline at end of file diff --git a/content/srcgen-fba/nuget.config b/content/srcgen-fba/nuget.config new file mode 100644 index 0000000..12dd92d --- /dev/null +++ b/content/srcgen-fba/nuget.config @@ -0,0 +1,6 @@ + + + + + + From bc1ab80050da3fff8266974acab7986eb6c514f3 Mon Sep 17 00:00:00 2001 From: naratteu Date: Thu, 28 May 2026 23:35:08 +0900 Subject: [PATCH 2/2] srcgen-fba/template --- content/srcgen-fba/.template.config/template.json | 14 ++++++++++++++ content/srcgen-fba/{Test.cs => Sample.Test.cs} | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 content/srcgen-fba/.template.config/template.json rename content/srcgen-fba/{Test.cs => Sample.Test.cs} (87%) diff --git a/content/srcgen-fba/.template.config/template.json b/content/srcgen-fba/.template.config/template.json new file mode 100644 index 0000000..05e303e --- /dev/null +++ b/content/srcgen-fba/.template.config/template.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "naratteu", + "classifications": [ "SourceGenerator", "FBA" ], + "identity": "srcgen-fba", + "name": "SourceGenerator (File-based App)", + "shortName": "srcgen-fba", + "sourceName": "Sample", + "preferNameDirectory": true, + "tags": { + "language": "C#", + "type": "project" + } +} \ No newline at end of file diff --git a/content/srcgen-fba/Test.cs b/content/srcgen-fba/Sample.Test.cs similarity index 87% rename from content/srcgen-fba/Test.cs rename to content/srcgen-fba/Sample.Test.cs index 2d43a7a..9f661a7 100644 --- a/content/srcgen-fba/Test.cs +++ b/content/srcgen-fba/Sample.Test.cs @@ -8,5 +8,5 @@ /* dotnet pack Sample.cs -p:Version=0.0.1 -dotnet Test.cs +dotnet Sample.Test.cs */ \ No newline at end of file