netstandard2.0
<IsRoslynComponent>true</IsRoslynComponent>
[Generator]
#pragma warning disable RS1036 // Specify analyzer banned API enforcement setting
public class HelloWorldGenerator : IIncrementalGenerator
#pragma warning restore RS1036 // Specify analyzer banned API enforcement setting
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context
.RegisterPostInitializationOutput(i =>
{
i.AddEmbeddedAttributeDefinition();// π Add the definition
i.AddSource("MyExampleAttribute.g.cs", @"
namespace HelloWorld
{
// π Use the attribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
internal class MyExampleAttribute: global::System.Attribute {}
}");
});
// ... generator implementaation
}
}