Skip to content

Commit

Permalink
Merge latest from main
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerav committed May 29, 2023
2 parents c5ad6e6 + cc81763 commit 31bc530
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 39 deletions.
3 changes: 0 additions & 3 deletions src/ExpressionDebugger/ExpressionDebugger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExpressionTranslator\ExpressionTranslator.csproj" />
Expand Down
12 changes: 0 additions & 12 deletions src/ExpressionTranslator/ExpressionTranslator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
<Reference Include="System" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Mapster.Async/Mapster.Async.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
Expand Down
3 changes: 0 additions & 3 deletions src/Mapster.Core/Mapster.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
<AssemblyOriginatorKeyFile>Mapster.Core.snk</AssemblyOriginatorKeyFile>
<RootNamespace>Mapster</RootNamespace>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<AssemblyOriginatorKeyFile>Mapster.DependencyInjection.snk</AssemblyOriginatorKeyFile>
<Version>1.0.1-pre02</Version>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.ComponentModel" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion src/Mapster.Tests/WhenMappingRecordTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public void Map_RecordType()
dest.Age.ShouldBe(10);
}

[TestMethod]
public void Map_RecordType_CapitalizationChanged()
{
TypeAdapterConfig<RecordType, RecordTypeDto>.NewConfig()
.Map(dest => dest.SpecialID, src => src.Id)
.Compile();

var source = new RecordType(Guid.NewGuid(), DayOfWeek.Monday);
var dest = source.Adapt<RecordTypeDto>();

dest.SpecialID.ShouldBe(source.Id);
}

public class SimplePoco
{
public Guid Id { get; set; }
Expand All @@ -49,7 +62,7 @@ public class SimpleDto
public string Name { get; set; }
}

public class RecordType
public record RecordType
{
public RecordType(Guid id, DayOfWeek day, string name = "foo", int age = 10)
{
Expand All @@ -64,5 +77,7 @@ public RecordType(Guid id, DayOfWeek day, string name = "foo", int age = 10)
public int Age { get; }
public DayOfWeek Day { get; }
}

public record RecordTypeDto(Guid SpecialID);
}
}
42 changes: 40 additions & 2 deletions src/Mapster.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using CommandLine;
using ExpressionDebugger;
using Mapster.Models;
Expand Down Expand Up @@ -495,8 +496,7 @@ private static void GenerateExtensionMethods(MapType mapType, TypeAdapterConfig
{
//add type name to prevent duplication
translator.Translate(entityType);
var destName = translator.Translate(tuple.Destination);
destName = destName.Split('.').Last();
var destName = GetMethodNameFromType(tuple.Destination);

var name = tuple.Destination.Name == entityType.Name
? destName
Expand All @@ -522,5 +522,43 @@ private static void GenerateExtensionMethods(MapType mapType, TypeAdapterConfig
"ProjectTo" + name);
}
}

private static string GetMethodNameFromType(Type type) => GetMethodNameFromType(new StringBuilder(), type).ToString();

private static StringBuilder GetMethodNameFromType(StringBuilder sb, Type type)
{
foreach (var subType in type.GenericTypeArguments)
{
GetMethodNameFromType(sb, subType);
}

if (type.IsArray)
{
GetMethodNameFromType(sb, type.GetElementType()!);
sb.Append("Array");
return sb;
}

var name = type.Name;
var i = name.IndexOf('`');
if (i>0) name = name.Remove(i);
name = name switch
{
"Nullable" => "",
"SByte" => "Sbyte",
"Int16" => "Short",
"UInt16" => "Ushort",
"Int32" => "Int",
"UInt32" => "Uint",
"Int64" => "Long",
"UInt64" => "Ulong",
"Single" => "Float",
"Boolean" => "Bool",
_ => name,
};

if (!string.IsNullOrEmpty(name)) sb.Append(name);
return sb;
}
}
}
11 changes: 0 additions & 11 deletions src/Mapster/Mapster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,12 @@
<PackageProjectUrl>https://github.com/MapsterMapper/Mapster</PackageProjectUrl>
<RepositoryUrl>https://github.com/MapsterMapper/Mapster</RepositoryUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.1</NetStandardImplicitPackageVersion>
<IsPackable>true</IsPackable>
<RootNamespace>Mapster</RootNamespace>
<Version>7.4.0-pre06</Version>
<Nullable>enable</Nullable>
<NoWarn>1701;1702;8618</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.Linq.Queryable" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Mapster/Settings/ValueAccessingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class ValueAccessingStrategy
Expression? getter = null;
foreach (var resolver in resolvers)
{
if (!destinationMember.Name.Equals(resolver.DestinationMemberName))
if (!destinationMember.Name.Equals(resolver.DestinationMemberName, StringComparison.InvariantCultureIgnoreCase))
continue;

var invoke = resolver.GetInvokingExpression(source, arg.MapType);
Expand Down
4 changes: 2 additions & 2 deletions src/Mapster/TypeAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static ITypeAdapterBuilder<TSource> BuildAdapter<TSource>(this TSource so
/// <typeparam name="TDestination">Destination type.</typeparam>
/// <param name="source">Source object to adapt.</param>
/// <returns>Adapted destination type.</returns>
public static TDestination Adapt<TDestination>(this object source)
public static TDestination Adapt<TDestination>(this object? source)
{
return Adapt<TDestination>(source, TypeAdapterConfig.GlobalSettings);
}
Expand All @@ -33,7 +33,7 @@ public static TDestination Adapt<TDestination>(this object source)
/// <param name="source">Source object to adapt.</param>
/// <param name="config">Configuration</param>
/// <returns>Adapted destination type.</returns>
public static TDestination Adapt<TDestination>(this object source, TypeAdapterConfig config)
public static TDestination Adapt<TDestination>(this object? source, TypeAdapterConfig config)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (source == null)
Expand Down

0 comments on commit 31bc530

Please sign in to comment.