Skip to content

Commit

Permalink
AutoMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
kkgonsovsky committed Apr 5, 2023
1 parent b04b45f commit e0b6c43
Show file tree
Hide file tree
Showing 439 changed files with 1,102 additions and 18,037 deletions.
7 changes: 6 additions & 1 deletion src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ public enum StronglyTypedIdConverter
/// </summary>
SwaggerSchemaFilter = 64,

/// <summary>
/// Creates a AutoMapper bidirectional converters
/// </summary>
AutoMapper = 128,

}
}
}
9 changes: 9 additions & 0 deletions src/StronglyTypedIds/EmbeddedSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_Convertible.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_StronglyTypedId.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_SwaggerSchemaFilter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_AutoMapperTypeConverter.cs"),
false
);

Expand All @@ -45,6 +46,7 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_Convertible.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_StronglyTypedId.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_SwaggerSchemaFilter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_AutoMapperTypeConverter.cs"),
false
);

Expand All @@ -61,6 +63,7 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_Convertible.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_StronglyTypedId.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_SwaggerSchemaFilter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_AutoMapperTypeConverter.cs"),
false
);

Expand All @@ -77,6 +80,7 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_Convertible.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_StronglyTypedId.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_SwaggerSchemaFilter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_AutoMapperTypeConverter.cs"),
false
);

Expand All @@ -93,6 +97,7 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_Convertible.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_StronglyTypedId.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_SwaggerSchemaFilter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_AutoMapperTypeConverter.cs"),
true
);

Expand All @@ -109,6 +114,7 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_Convertible.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_StronglyTypedId.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_SwaggerSchemaFilter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_AutoMapperTypeConverter.cs"),
false
);

Expand Down Expand Up @@ -142,6 +148,7 @@ public readonly struct ResourceCollection
public string TypeConverter { get; }
public string EfCoreValueConverter { get; }
public string DapperTypeHandler { get; }
public string AutoMapperTypeHandler { get; }
public string Comparable { get; }
public string Parsable { get; }
public string Convertible { get; }
Expand All @@ -161,6 +168,7 @@ public ResourceCollection(
string convertible,
string stronglyTypedId,
string swaggerSchemaFilter,
string autoMapperTypeHandler,
bool nullableEnable)
{
SwaggerSchemaFilter = swaggerSchemaFilter;
Expand All @@ -170,6 +178,7 @@ public ResourceCollection(
TypeConverter = typeConverter;
EfCoreValueConverter = efCoreValueConverter;
DapperTypeHandler = dapperTypeHandler;
AutoMapperTypeHandler = autoMapperTypeHandler;
Comparable = comparable;
Parsable = parsable;
Convertible = convertible;
Expand Down
6 changes: 6 additions & 0 deletions src/StronglyTypedIds/SourceGenerationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static string CreateId(
var useSystemTextJson = converters.IsSet(StronglyTypedIdConverter.SystemTextJson);
var useEfCoreValueConverter = converters.IsSet(StronglyTypedIdConverter.EfCoreValueConverter);
var useDapperTypeHandler = converters.IsSet(StronglyTypedIdConverter.DapperTypeHandler);
var useAutoMapperTypeHandler = converters.IsSet(StronglyTypedIdConverter.AutoMapper);

var useIEquatable = implementations.IsSet(StronglyTypedIdImplementations.IEquatable);
var useIComparable = implementations.IsSet(StronglyTypedIdImplementations.IComparable);
Expand Down Expand Up @@ -168,6 +169,11 @@ static string CreateId(
sb.AppendLine(resources.DapperTypeHandler);
}

if (useAutoMapperTypeHandler)
{
sb.AppendLine(resources.AutoMapperTypeHandler);
}

if (useTypeConverter)
{
sb.AppendLine(resources.TypeConverter);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#if !FAKE_CODE
public class AutoMapperTypeConverter : AutoMapper.ITypeConverter<TESTID, System.Guid>
{
public System.Guid Convert(TESTID source, System.Guid destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif
10 changes: 10 additions & 0 deletions src/StronglyTypedIds/Templates/Int/Int_AutoMapperTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#if !FAKE_CODE
public class AutoMapperTypeConverter : AutoMapper.ITypeConverter<TESTID, int>
{
public int Convert(TESTID source, int destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#if !FAKE_CODE
public class AutoMapperTypeConverter : AutoMapper.ITypeConverter<TESTID, long>
{
public long Convert(TESTID source, long destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#if !FAKE_CODE
public class AutoMapperTypeConverter : AutoMapper.ITypeConverter<TESTID, string?>
{
public string Convert(TESTID source, string destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#if !FAKE_CODE
public class AutoMapperTypeConverter : AutoMapper.ITypeConverter<TESTID, string?>
{
public string? Convert(TESTID source, string? destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#if !FAKE_CODE
public class AutoMapperTypeConverter : AutoMapper.ITypeConverter<TESTID, string>
{
public string Convert(TESTID source, string destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif
13 changes: 13 additions & 0 deletions test/StronglyTypedIds.IntegrationTests/AutoMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AutoMapper;

//FAKE STUB
public interface ITypeConverter<T, T2>
{

}

//FAKE STUB
public class ResolutionContext
{

}
3 changes: 2 additions & 1 deletion test/StronglyTypedIds.IntegrationTests/StronglyTypedId.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
public interface IStronglyTypedId<T> {
//FAKE STUB
public interface IStronglyTypedId<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net48;$(TargetFrameworks)</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks)</TargetFrameworks>
<IsPackable>false</IsPackable>
<Nullable>disable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;FAKE_CODE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;FAKE_CODE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\StronglyTypedIds\StronglyTypedIds.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\src\StronglyTypedIds.Attributes\StronglyTypedIds.Attributes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
Expand Down
6 changes: 5 additions & 1 deletion test/StronglyTypedIds.IntegrationTests/Types/LongId.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using StronglyTypedIds;
using AutoMapper;

namespace StronglyTypedIds.IntegrationTests.Types
{
Expand Down Expand Up @@ -42,4 +42,8 @@ public partial struct ComparableLongId { }

[StronglyTypedId(backingType: StronglyTypedIdBackingType.Long, implementations: StronglyTypedIdImplementations.IStronglyTypedId)]
public partial struct StronglyTypedIdLongId { }


[StronglyTypedId(backingType: StronglyTypedIdBackingType.Long, converters : StronglyTypedIdConverter.AutoMapper)]
public partial struct AutoMappedLongId { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace StronglyTypedIds
/// </summary>
SwaggerSchemaFilter = 64,

/// <summary>
/// Creates a AutoMapper bidirectional converters
/// </summary>
AutoMapper = 128,

}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace StronglyTypedIds
/// </summary>
SwaggerSchemaFilter = 64,

/// <summary>
/// Creates a AutoMapper bidirectional converters
/// </summary>
AutoMapper = 128,

}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace StronglyTypedIds
/// </summary>
SwaggerSchemaFilter = 64,

/// <summary>
/// Creates a AutoMapper bidirectional converters
/// </summary>
AutoMapper = 128,

}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace StronglyTypedIds
/// </summary>
SwaggerSchemaFilter = 64,

/// <summary>
/// Creates a AutoMapper bidirectional converters
/// </summary>
AutoMapper = 128,

}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace StronglyTypedIds
/// </summary>
SwaggerSchemaFilter = 64,

/// <summary>
/// Creates a AutoMapper bidirectional converters
/// </summary>
AutoMapper = 128,

}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@
#pragma warning restore CA2255


#if !FAKE_CODE
public class MyTestIdAutoMapperTypeConverter : AutoMapper.ITypeConverter<MyTestId, System.Guid>
{
public System.Guid Convert(MyTestId source, System.Guid destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif


class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@
#pragma warning restore CA2255


#if !FAKE_CODE
public class MyTestIdAutoMapperTypeConverter : AutoMapper.ITypeConverter<MyTestId, System.Guid>
{
public System.Guid Convert(MyTestId source, System.Guid destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif


class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@
#pragma warning restore CA2255


#if !FAKE_CODE
public class MyTestIdAutoMapperTypeConverter : AutoMapper.ITypeConverter<MyTestId, System.Guid>
{
public System.Guid Convert(MyTestId source, System.Guid destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif


class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@
#pragma warning restore CA2255


#if !FAKE_CODE
public class MyTestIdAutoMapperTypeConverter : AutoMapper.ITypeConverter<MyTestId, System.Guid>
{
public System.Guid Convert(MyTestId source, System.Guid destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif


class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@
#pragma warning restore CA2255


#if !FAKE_CODE
public class MyTestIdAutoMapperTypeConverter : AutoMapper.ITypeConverter<MyTestId, System.Guid>
{
public System.Guid Convert(MyTestId source, System.Guid destination, AutoMapper.ResolutionContext context)
{
return source.Value;
}
}
#endif


class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
Expand Down
Loading

0 comments on commit e0b6c43

Please sign in to comment.