-
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.
Generate GenerateAutomaticInterfaceAttribute instead of asking that o…
…f the user. See cookbook: https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.cookbook.md#generated-class
- Loading branch information
Colin Wilmans
committed
Apr 16, 2024
1 parent
7d87360
commit 45ef6ea
Showing
14 changed files
with
105 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,59 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31702.278 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomaticInterfaceExample", "AutomaticInterfaceExample\AutomaticInterfaceExample.csproj", "{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomaticInterface", "AutomaticInterface\AutomaticInterface.csproj", "{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomaticInterfaceAttribute", "AutomaticInterfaceAttribute\AutomaticInterfaceAttribute.csproj", "{ADEA885F-9F6F-443E-945A-512223AEFC11}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{96FEC8F8-B0D8-41C9-B9C4-6D1B221D6128}" | ||
ProjectSection(SolutionItems) = preProject | ||
Directory.Build.targets = Directory.Build.targets | ||
..\.github\workflows\action.yml = ..\.github\workflows\action.yml | ||
..\README.md = ..\README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNuget", "TestNuget\TestNuget.csproj", "{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
DebugGenerator|Any CPU = DebugGenerator|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.DebugGenerator|Any CPU.ActiveCfg = DebugGenerator|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.DebugGenerator|Any CPU.Build.0 = DebugGenerator|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.DebugGenerator|Any CPU.ActiveCfg = DebugGenerator|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.DebugGenerator|Any CPU.Build.0 = DebugGenerator|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{ADEA885F-9F6F-443E-945A-512223AEFC11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ADEA885F-9F6F-443E-945A-512223AEFC11}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ADEA885F-9F6F-443E-945A-512223AEFC11}.DebugGenerator|Any CPU.ActiveCfg = DebugGenerator|Any CPU | ||
{ADEA885F-9F6F-443E-945A-512223AEFC11}.DebugGenerator|Any CPU.Build.0 = DebugGenerator|Any CPU | ||
{ADEA885F-9F6F-443E-945A-512223AEFC11}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ADEA885F-9F6F-443E-945A-512223AEFC11}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.DebugGenerator|Any CPU.ActiveCfg = DebugGenerator|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.DebugGenerator|Any CPU.Build.0 = DebugGenerator|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.DebugGenerator|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.DebugGenerator|Any CPU.Build.0 = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B144CF18-21D8-4CB6-9847-DDE7451543D4} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34728.123 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomaticInterfaceExample", "AutomaticInterfaceExample\AutomaticInterfaceExample.csproj", "{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomaticInterface", "AutomaticInterface\AutomaticInterface.csproj", "{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{96FEC8F8-B0D8-41C9-B9C4-6D1B221D6128}" | ||
ProjectSection(SolutionItems) = preProject | ||
..\.github\workflows\action.yml = ..\.github\workflows\action.yml | ||
Directory.Build.targets = Directory.Build.targets | ||
..\README.md = ..\README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestNuget", "TestNuget\TestNuget.csproj", "{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
DebugGenerator|Any CPU = DebugGenerator|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.DebugGenerator|Any CPU.ActiveCfg = DebugGenerator|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.DebugGenerator|Any CPU.Build.0 = DebugGenerator|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AFDAB373-7268-4A1B-ABAF-EA076C3B2B4C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.DebugGenerator|Any CPU.ActiveCfg = DebugGenerator|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.DebugGenerator|Any CPU.Build.0 = DebugGenerator|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AA3F5AAE-44B7-4F33-8152-A5251B51AD79}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.DebugGenerator|Any CPU.ActiveCfg = DebugGenerator|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.DebugGenerator|Any CPU.Build.0 = DebugGenerator|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E267C5B3-44DD-4D26-A2F7-5FDF92FF28D5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.DebugGenerator|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.DebugGenerator|Any CPU.Build.0 = Debug|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E7CF6623-54D8-4A40-A1B1-CE078551EFE1}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B144CF18-21D8-4CB6-9847-DDE7451543D4} | ||
EndGlobalSection | ||
EndGlobal |
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
8 changes: 0 additions & 8 deletions
8
AutomaticInterface/AutomaticInterfaceAttribute/AutomaticInterfaceAttribute.csproj
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
AutomaticInterface/AutomaticInterfaceAttribute/GenerateAutomaticInterfaceAttribute.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
2 changes: 1 addition & 1 deletion
2
AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.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
2 changes: 1 addition & 1 deletion
2
AutomaticInterface/AutomaticInterfaceExample/InterfaceExample.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
14 changes: 14 additions & 0 deletions
14
AutomaticInterface/TestNuget/RemoveThisOnNextVersionAttribute.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,14 @@ | ||
using System; | ||
|
||
namespace AutomaticInterface | ||
{ | ||
/// <summary> | ||
/// Use source generator to automatically create a Interface from this class | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
[Obsolete("This attribute is obsolete. Use generated attribute instead.", false)] | ||
internal sealed class GenerateAutomaticInterfaceAttribute : Attribute | ||
{ | ||
internal GenerateAutomaticInterfaceAttribute(string namespaceName = "") { } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using AutomaticInterfaceAttribute; | ||
using AutomaticInterface; | ||
|
||
namespace TestNuget | ||
{ | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ This interface will be generated on each subsequent build, eliminating the the f | |
## Example | ||
|
||
```c# | ||
using AutomaticInterfaceAttribute; | ||
using AutomaticInterface; | ||
using System; | ||
|
||
namespace AutomaticInterfaceExample | ||
|
@@ -85,7 +85,7 @@ This will create this interface: | |
```C# | ||
#nullable enable | ||
using System.CodeDom.Compiler; | ||
using AutomaticInterfaceAttribute; | ||
using AutomaticInterface; | ||
using System; | ||
|
||
/// <summary> | ||
|
@@ -126,9 +126,8 @@ namespace AutomaticInterfaceExample | |
## How to use it? | ||
|
||
1. Install the nuget: `dotnet add package AutomaticInterface` | ||
2. Create an Attribute with the Name `[GenerateAutomaticInterface]`. You can just copy the minimal code from this Repo (see the `AutomaticInterfaceAttribute` project). It's the easiest way to get that attribute because you cannot reference any code from the analyzer package. | ||
3. Let your class implement the interface, e.g. `SomeClass: ISomeClass` | ||
4. Build Solution, the Interface should now be available. | ||
2. Let your class implement the interface, e.g. `SomeClass: ISomeClass` | ||
3. Build Solution, the Interface should now be available. | ||
|
||
Any errors? Ping me at: [email protected] | ||
|
||
|