Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/AutoMapper/ConstructorMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class ConstructorParameterMap : MemberMap
public ConstructorParameterMap(TypeMap typeMap, ParameterInfo parameter, MemberInfo[] sourceMembers) : base(typeMap)
{
Parameter = parameter;
var parameterType = parameter.ParameterType;
DestinationType = parameterType.IsByRef ? parameterType.GetElementType() : parameterType;
if (sourceMembers.Length > 0)
{
MapByConvention(sourceMembers);
Expand All @@ -80,7 +82,7 @@ public ConstructorParameterMap(TypeMap typeMap, ParameterInfo parameter, MemberI
}
}
public ParameterInfo Parameter { get; }
public override Type DestinationType => Parameter.ParameterType;
public override Type DestinationType { get; protected set; }
public override IncludedMember IncludedMember { get; protected set; }
public override MemberInfo[] SourceMembers { get; set; }
public override string DestinationName => Parameter.Name;
Expand Down
41 changes: 41 additions & 0 deletions src/UnitTests/Bug/ByrefConstructorParameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace AutoMapper.UnitTests.Bug;

public class ByrefConstructorParameter : AutoMapperSpecBase
{
private Destination _destination;

class Source
{
public TimeSpan X { get; set; }
}

class Destination
{
public Destination(in TimeSpan x)
{
Y = x;
}

public TimeSpan Y { get; }
}

protected override MapperConfiguration CreateConfiguration() => new(cfg =>
{
cfg.CreateMap<Source, Destination>();
});

protected override void Because_of()
{
var source = new Source
{
X = TimeSpan.FromSeconds(17)
};
_destination = Mapper.Map<Destination>(source);
}

[Fact]
public void should_just_work()
{
_destination.Y.ShouldBe(TimeSpan.FromSeconds(17));
}
}