Skip to content

Commit

Permalink
feat: decorate all emitted mapper types with GeneratedCodeAttribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer committed Jan 18, 2024
1 parent cdee78b commit c42b311
Show file tree
Hide file tree
Showing 202 changed files with 449 additions and 192 deletions.
5 changes: 5 additions & 0 deletions docs/docs/configuration/generated-source.mdx
Expand Up @@ -63,3 +63,8 @@ You won't see the updated mapper code or mapper diagnostics until you perform a
This is done for performance reasons,
otherwise the IDE could become laggy.
:::

## Excluding from code coverage

Mapperly decorates each generated mapper type with the `GeneratedCodeAttribute`. This attribute can be used
to configure code coverage tooling to either include or exclude the generated mapper code in the coverage report.
26 changes: 26 additions & 0 deletions src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.GeneratedCode.cs
@@ -0,0 +1,26 @@
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace Riok.Mapperly.Emit.Syntax;

public partial struct SyntaxFactoryHelper
{
private const string GeneratedCodeAttributeName = "global::System.CodeDom.Compiler.GeneratedCode";
private static readonly AssemblyName _generatorAssemblyName = typeof(SyntaxFactoryHelper).Assembly.GetName();

private SyntaxList<AttributeListSyntax> GeneratedCodeAttributeList()
{
var arguments = CommaSeparatedList(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(_generatorAssemblyName.Name))),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(_generatorAssemblyName.Version.ToString())))
);

var attribute = Attribute(IdentifierName(GeneratedCodeAttributeName))
.WithArgumentList(AttributeArgumentList(CommaSeparatedList(arguments)));

return SingletonList(AttributeList(SingletonSeparatedList(attribute)).AddTrailingLineFeed(Indentation));
}
}
Expand Up @@ -24,6 +24,7 @@ public ClassDeclarationSyntax Class(string name, SyntaxTokenList modifiers, Synt
.WithKeyword(TrailingSpacedToken(SyntaxKind.ClassKeyword))
.WithOpenBraceToken(LeadingLineFeedToken(SyntaxKind.OpenBraceToken))
.WithCloseBraceToken(LeadingLineFeedToken(SyntaxKind.CloseBraceToken))
.WithAttributeLists(GeneratedCodeAttributeList())
.AddLeadingLineFeed(Indentation);
}
}
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class CircularReferenceMapper
{
public static partial global::Riok.Mapperly.IntegrationTests.Dto.CircularReferenceDto ToDto(global::Riok.Mapperly.IntegrationTests.Models.CircularReferenceObject obj)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class DeepCloningMapper
{
public static partial global::Riok.Mapperly.IntegrationTests.Models.IdObject Copy(global::Riok.Mapperly.IntegrationTests.Models.IdObject src)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class DeepCloningMapper
{
public static partial global::Riok.Mapperly.IntegrationTests.Models.IdObject Copy(global::Riok.Mapperly.IntegrationTests.Models.IdObject src)
Expand Down
Expand Up @@ -2,6 +2,7 @@
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class BaseMapper
{
public virtual partial long IntToLong(int value)
Expand Down
Expand Up @@ -2,6 +2,7 @@
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class DerivedMapper
{
public override partial long IntToLong(int value)
Expand Down
Expand Up @@ -2,6 +2,7 @@
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class DerivedMapper2
{
public sealed override partial long IntToLong(int value)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class EnumMapper
{
public static partial global::Riok.Mapperly.IntegrationTests.Mapper.Enum2 Map(global::Riok.Mapperly.IntegrationTests.Mapper.Enum1 e)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class TestMapper
{
public partial int DirectInt(int value)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class TestMapper
{
public partial int DirectInt(int value)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class TestMapper
{
public partial int DirectInt(int value)
Expand Down Expand Up @@ -542,6 +543,7 @@ private string MapToString1(global::Riok.Mapperly.IntegrationTests.Dto.TestEnumD
}
}

[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
static file class UnsafeAccessor
{
[global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "get_PrivateValue")]
Expand Down
@@ -1,11 +1,14 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class NestedTestMapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class TestNesting
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class NestedMapper
{
public static partial int ToInt(decimal value)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class ProjectionMapper
{
public static partial global::System.Linq.IQueryable<global::Riok.Mapperly.IntegrationTests.Dto.TestObjectDtoProjection> ProjectToDto(this global::System.Linq.IQueryable<global::Riok.Mapperly.IntegrationTests.Models.TestObjectProjection> q)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class ProjectionMapper
{
public static partial global::System.Linq.IQueryable<global::Riok.Mapperly.IntegrationTests.Dto.TestObjectDtoProjection> ProjectToDto(this global::System.Linq.IQueryable<global::Riok.Mapperly.IntegrationTests.Models.TestObjectProjection> q)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class StaticTestMapper
{
public static partial int DirectInt(int value)
Expand Down
@@ -1,7 +1,8 @@
// <auto-generated />
// <auto-generated />
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class StaticTestMapper
{
public static partial int DirectInt(int value)
Expand Down
Expand Up @@ -2,6 +2,7 @@
#nullable enable
namespace Riok.Mapperly.IntegrationTests.Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public static partial class UseExternalMapper
{
public static partial global::Riok.Mapperly.IntegrationTests.Dto.IdObjectDto Map(global::Riok.Mapperly.IntegrationTests.Models.IdObject source)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial void Map(global::A src, global::B trg)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial void Map(global::A src, global::B trg)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial void Map(global::A src, global::B trg)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial void Map(global::A src, global::B trg)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial void Map(global::A? src, global::B? trg)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial void Map(global::A? src, global::B trg)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B Map(global::A src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B Map(global::A src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B Map(global::A src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B Map(global::A src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::System.Collections.Generic.IEnumerable<global::B> Map(global::System.Collections.Generic.IEnumerable<global::A> source)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B Map(global::A source)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B Map(global::A src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B? Map(global::A? src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial global::B Map(global::A? src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
public partial object Map(object src)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
private partial global::A Map(global::System.Collections.Generic.IDictionary<string, int> source)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
private partial global::B Map(global::A source)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
private partial global::B Map(global::A source)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
private partial global::B Map(global::A source)
Expand Down
@@ -1,6 +1,7 @@
//HintName: Mapper.g.cs
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial class Mapper
{
private partial global::B Map(global::A source)
Expand Down

0 comments on commit c42b311

Please sign in to comment.