Skip to content

Commit

Permalink
feat: add auto generate tag
Browse files Browse the repository at this point in the history
  • Loading branch information
EngRajabi committed Mar 29, 2024
1 parent c320d0d commit eb5796c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions Supernova.Enum.Generators/EnumSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public void Execute(GeneratorExecutionContext context)
// Debugger.Launch();
// }
//#endif
context.AddSource($"{SourceGeneratorHelper.AttributeName}Attribute.g.cs", SourceText.From($@"
context.AddSource($"{SourceGeneratorHelper.AttributeName}Attribute.g.cs", SourceText.From(
$@"// <auto-generated />
using System;
using System.CodeDom.Compiler;
namespace {SourceGeneratorHelper.NameSpace}
Expand Down Expand Up @@ -107,14 +108,18 @@ public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute
}
}

var sourceBuilder = new StringBuilder($@"using System;

var sourceBuilder = new StringBuilder($@"// <auto-generated />
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace {SourceGeneratorHelper.NameSpace}
{{
/// <summary>
/// Provides extension methods for operations related to the <see cref=""global::{symbol.FullName()}"" /> enumeration.
/// </summary>
/// </summary>
[GeneratedCodeAttribute(""Supernova.Enum.Generators"", null)]
{symbol.DeclaredAccessibility.ToString("G").ToLower()} static class {symbol.Name}EnumExtensions
{{");

Expand Down Expand Up @@ -147,8 +152,8 @@ namespace {SourceGeneratorHelper.NameSpace}

//GetLength
GetLengthFast(sourceBuilder, symbol, e);


//TryParse
TryParseFast(sourceBuilder, e, symbol);

Expand Down Expand Up @@ -399,7 +404,7 @@ private static void GetLengthFast(StringBuilder sourceBuilder, ISymbol symbol, E
}
");
}

private static void TryParseFast(StringBuilder sourceBuilder, EnumDeclarationSyntax e, ISymbol symbol)
{
sourceBuilder.Append($@"
Expand Down
6 changes: 3 additions & 3 deletions Supernova.Enum.Generators/Extensions/SymbolExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using System;

namespace Supernova.Enum.Generators.Extensions;

Expand All @@ -18,7 +18,7 @@ public static string FullName(this ISymbol symbol)
// TODO: Use NamespaceSymbolExtensions.FullName after Merge of #70
return $"{symbol.ContainingNamespace.FullNamespace()}.{symbol.Name}";
}

/// <summary>
/// Gets the full name of the namespace, including parent namespaces.
/// </summary>
Expand Down

0 comments on commit eb5796c

Please sign in to comment.