GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - LokiMidgard/SourceGenerator.Helper.CopyCode: A simple Generator that generates a string representation to an anotatead Type

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
SourceGenerator.Helper.CopyCode
SourceGenerator.Helper.CopyCode
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
SourceGenerator.Helper.CopyCode.sln
SourceGenerator.Helper.CopyCode.sln
 
 

Repository files navigation

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…
    }
}

About

A simple Generator that generates a string representation to an anotatead Type

Topics

csharp-sourcegeneratorsourcegenerator

Resources

Readme
Unlicense
Activity

Stars

9 stars

Watchers

1 watching

Forks

0 forks
Report repository

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.