-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from crwsolutions/master
Also generate the IgnoreAutomaticInterfaceAttribute
- Loading branch information
Showing
5 changed files
with
80 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
AutomaticInterface/AutomaticInterface/RegisterAttributesExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Text; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace AutomaticInterface; | ||
|
||
internal static class RegisterAttributesExtensions | ||
{ | ||
public static IncrementalGeneratorInitializationContext RegisterDefaultAttribute( | ||
this IncrementalGeneratorInitializationContext context | ||
) | ||
{ | ||
context.RegisterPostInitializationOutput(static postInitializationContext => | ||
{ | ||
postInitializationContext.AddSource( | ||
$"{AutomaticInterfaceGenerator.DefaultAttributeName}.Attribute.g.cs", | ||
SourceText.From( | ||
$$$""" | ||
// <auto-generated /> | ||
using System; | ||
namespace AutomaticInterface | ||
{ | ||
/// <summary> | ||
/// Use source generator to automatically create a Interface from this class | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
internal sealed class {{{AutomaticInterfaceGenerator.DefaultAttributeName}}}Attribute : Attribute | ||
{ | ||
internal {{{AutomaticInterfaceGenerator.DefaultAttributeName}}}Attribute(string namespaceName = "") { } | ||
} | ||
} | ||
""", | ||
Encoding.UTF8 | ||
) | ||
); | ||
}); | ||
return context; | ||
} | ||
|
||
public static IncrementalGeneratorInitializationContext RegisterIgnoreAttribute( | ||
this IncrementalGeneratorInitializationContext context | ||
) | ||
{ | ||
context.RegisterPostInitializationOutput(static postInitializationContext => | ||
{ | ||
postInitializationContext.AddSource( | ||
$"{AutomaticInterfaceGenerator.IgnoreAutomaticInterfaceAttributeName}.Attribute.g.cs", | ||
SourceText.From( | ||
$$$""" | ||
// <auto-generated /> | ||
using System; | ||
namespace AutomaticInterface | ||
{ | ||
/// <summary> | ||
/// Ignore this member in a generated Interface from this class | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event)] | ||
internal sealed class {{{AutomaticInterfaceGenerator.IgnoreAutomaticInterfaceAttributeName}}}Attribute : Attribute | ||
{ | ||
internal {{{AutomaticInterfaceGenerator.IgnoreAutomaticInterfaceAttributeName}}}Attribute() { } | ||
} | ||
} | ||
""", | ||
Encoding.UTF8 | ||
) | ||
); | ||
}); | ||
return context; | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
AutomaticInterface/AutomaticInterfaceAttribute/IgnoreAutomaticInterfaceAttribute.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters