Add <auto-generated> (#24)

This commit is contained in:
Stef Heyenrath
2021-08-05 21:34:50 +02:00
committed by GitHub
parent 2a56acea6e
commit 8d43c73816
7 changed files with 83 additions and 53 deletions
@@ -30,7 +30,7 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
var interfaceName = targetClassSymbol.ResolveInterfaceNameWithOptionalTypeConstraints(pd.InterfaceName);
var file = new FileData(
$"{pd.FileName}.cs",
$"{pd.FileName}.g.cs",
CreatePartialInterfaceCode(pd.Namespace, targetClassSymbol, interfaceName, pd.ProxyAll)
);
@@ -39,7 +39,17 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
return file;
}
private string CreatePartialInterfaceCode(string ns, INamedTypeSymbol targetClassSymbol, string interfaceName, bool proxyAll) => $@"using System;
private string CreatePartialInterfaceCode(string ns, INamedTypeSymbol targetClassSymbol, string interfaceName, bool proxyAll) => $@"//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------
#nullable enable
using System;
namespace {ns}
{{
@@ -51,7 +61,8 @@ namespace {ns}
{GenerateEvents(targetClassSymbol)}
}}
}}";
}}
#nullable disable";
private string GenerateProperties(INamedTypeSymbol targetClassSymbol, bool proxyAll)
{
@@ -1,4 +1,4 @@
namespace ProxyInterfaceSourceGenerator.FileGenerators
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal class ProxyAttributeGenerator : IFileGenerator
{
@@ -6,7 +6,16 @@
public FileData GenerateFile()
{
return new FileData($"{ClassName}.cs", $@"using System;
return new FileData($"{ClassName}.g.cs", $@"//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------
using System;
namespace ProxyInterfaceGenerator
{{
@@ -32,7 +32,7 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
var constructorName = $"{targetClassSymbol.Name}Proxy";
var file = new FileData(
$"{pd.FileName}Proxy.cs",
$"{pd.FileName}Proxy.g.cs",
CreateProxyClassCode(pd.Namespace, targetClassSymbol, interfaceName, className, constructorName)
);
@@ -41,7 +41,17 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
return file;
}
private string CreateProxyClassCode(string ns, INamedTypeSymbol targetClassSymbol, string interfaceName, string className, string constructorName) => $@"using System;
private string CreateProxyClassCode(string ns, INamedTypeSymbol targetClassSymbol, string interfaceName, string className, string constructorName) => $@"//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------
#nullable enable
using System;
using AutoMapper;
namespace {ns}
@@ -65,7 +75,8 @@ namespace {ns}
{GeneratePrivateAutoMapper()}
}}
}}";
}}
#nullable disable";
private string GeneratePrivateAutoMapper()
{
return _context.ReplacedTypes.Count == 0 ? string.Empty : " private readonly IMapper _mapper;";
@@ -7,7 +7,7 @@ using ProxyInterfaceSourceGenerator.SyntaxReceiver;
namespace ProxyInterfaceSourceGenerator
{
[Generator]
public class ProxyInterfaceCodeGenerator : ISourceGenerator
internal class ProxyInterfaceCodeGenerator : ISourceGenerator
{
private readonly ProxyAttributeGenerator _proxyAttributeGenerator = new ProxyAttributeGenerator();
@@ -1,53 +1,52 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>0.0.8</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<Authors>Stef Heyenrath</Authors>
<Description></Description>
<Title>ProxyInterfaceGenerator</Title>
<PackageId>ProxyInterfaceGenerator</PackageId>
<Description>This project uses Source Generation to generate an interface and a Proxy class for classes. This makes it possible to wrap external classes which do not have an interface, in a Proxy class which makes it easier to Mock and use DI.</Description>
<PackageTags>class;interface;proxy;SourceGenerator;Analyzer;Generation;Generate;wrap</PackageTags>
<PropertyGroup>
<Version>0.0.9</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<Authors>Stef Heyenrath</Authors>
<Description></Description>
<Title>ProxyInterfaceGenerator</Title>
<PackageId>ProxyInterfaceGenerator</PackageId>
<Description>This project uses Source Generation to generate an interface and a Proxy class for classes. This makes it possible to wrap external classes which do not have an interface, in a Proxy class which makes it easier to Mock and use DI.</Description>
<PackageTags>class;interface;proxy;SourceGenerator;Analyzer;Generation;Generate;wrap</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>See ReleaseNotes.md</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/StefH/ProxyInterfaceGenerator</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/StefH/ProxyInterfaceGenerator</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>See ReleaseNotes.md</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/StefH/ProxyInterfaceGenerator</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/StefH/ProxyInterfaceGenerator</RepositoryUrl>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{12344228-91F4-4502-9595-39584E5ABB34}</ProjectGuid>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{12344228-91F4-4502-9595-39584E5ABB34}</ProjectGuid>
<IncludeBuildOutput>false</IncludeBuildOutput>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<IncludeBuildOutput>false</IncludeBuildOutput>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<!--<PackageReference Include="AnyOf" Version="0.0.12" />-->
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<None Remove="bin\Debug\netstandard2.0\\ProxyInterfaceGenerator.dll" />
<None Remove="bin\Release\netstandard2.0\\ProxyInterfaceGenerator.dll" />
</ItemGroup>
<ItemGroup>
<None Remove="bin\Debug\netstandard2.0\\ProxyInterfaceGenerator.dll" />
<None Remove="bin\Release\netstandard2.0\\ProxyInterfaceGenerator.dll" />
</ItemGroup>
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
</Project>