NeVeSpl / NSourceGenerators

MIT License
0 stars 0 forks source link
roslyn

NSourceGenerators

NSourceGenerators.CodeToString

Nuget

Roslyn source generator that turns c# source code decorated with [CodeToString] atribute into a string literal.

A simple console app, that writes its own code to console output:

Input

using NSourceGenerators;

namespace CodeToString.Sample
{
    [CodeToString]
    partial class Program
    {
        [CodeToString("MainKey")]       
        static void Main(string[] args)
        {
            var programCode = CodeToStringRepo.GetText("CodeToString.Sample.Program");
            Console.WriteLine(programCode);

            var mainCode = CodeToStringRepo.GetText("MainKey");
            Console.WriteLine(mainCode);
        }        
    }
}

Output

    partial class Program
    {
        [CodeToString("MainKey")]
        static void Main(string[] args)
        {
            var programCode = CodeToStringRepo.GetText("CodeToString.Sample.Program");
            Console.WriteLine(programCode);

            var mainCode = CodeToStringRepo.GetText("MainKey");
            Console.WriteLine(mainCode);
        }
    }
        static void Main(string[] args)
        {
            var programCode = CodeToStringRepo.GetText("CodeToString.Sample.Program");
            Console.WriteLine(programCode);

            var mainCode = CodeToStringRepo.GetText("MainKey");
            Console.WriteLine(mainCode);
        }