SourceGenerator.Helper.CopyCode 0.0.2

dotnet add package SourceGenerator.Helper.CopyCode --version 0.0.2                
NuGet\Install-Package SourceGenerator.Helper.CopyCode -Version 0.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SourceGenerator.Helper.CopyCode" Version="0.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SourceGenerator.Helper.CopyCode --version 0.0.2                
#r "nuget: SourceGenerator.Helper.CopyCode, 0.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SourceGenerator.Helper.CopyCode as a Cake Addin
#addin nuget:?package=SourceGenerator.Helper.CopyCode&version=0.0.2

// Install SourceGenerator.Helper.CopyCode as a Cake Tool
#tool nuget:?package=SourceGenerator.Helper.CopyCode&version=0.0.2                

NuGet GitHub license

SourceGenerator.Helper.CopyCode

This Generator is intendede to generate text that a source generator can use to emit source to its generation.

E.g. Instead of writing a String that contains the definiton of an Attribute (without syntax highlighting and checking). You can generate the attribute normaly in Code and anotate it wit [SourceGenerator.Helper.CopyCode.Copy]. Attributes defined on that Type will also be copied, if they are defined below the [SourceGenerator.Helper.CopyCode.Copy]-Attribute.

Assume you have the following attribute:


namespace SourceGenerator.Helper.CopyCode.Example;

[SourceGenerator.Helper.CopyCode.Copy]
[System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
internal sealed class MyGeneratorAttribute : Attribute {

}

then the generator will generate:

// <auto-generated/>
#nullable enable
namespace SourceGenerator.Helper.CopyCode;
internal  static partial class Copy {
    public const string SourceGeneratorHelperCopyCodeExampleMyGeneratorAttribute = """
        // <auto-generated/>
        #nullable enable
        
        namespace SourceGenerator.Helper.CopyCode.Example;
        [System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
        internal sealed class MyGeneratorAttribute : Attribute
        {
        }
        """;
}

And your Generator can emit it:

[Generator(LanguageNames.CSharp)]
public class MyGenerator : IIncrementalGenerator {
    public void Initialize(IncrementalGeneratorInitializationContext context) {
        context.RegisterPostInitializationOutput(context => context.AddSource("attribute.g.cs", SourceGenerator.Helper.CopyCode.Copy.SourceGeneratorHelperCopyCodeExampleMyGeneratorAttribute ));
        // The rest of your generator�
    }
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2 198 5/9/2024
0.0.1 347 8/12/2023