Skip to content

Commit

Permalink
Remove mod in ObjectAdapter and new Test When Object is inside field …
Browse files Browse the repository at this point in the history
…of other Type
  • Loading branch information
DocSvartz committed Oct 21, 2023
1 parent d7c73e3 commit e0ae818
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
41 changes: 40 additions & 1 deletion src/Mapster.Tests/WhenMappingObjectRegression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void UpdateManyDest()
}

[TestMethod]
public void UpdateToRealObject() /// Warning potential Infinity Loop in ObjectAdapter!!!
public void UpdateToRealObject()
{
var source = new Source524 { X1 = 123 };
var RealObject = new Object();
Expand All @@ -66,6 +66,39 @@ public void RealObjectCastToDestination() /// Warning potential Infinity Loop in
((Source524)_result).X1.ShouldBe(source.X1);
}

[TestMethod]
public void UpdateObjectInsaider()
{
var _source = new InsaderObject() { X1 = 1 };
var _Destination = new InsaderObject() { X1 = 2 };

var _result = _source.Adapt(_Destination);

_result.X1.ShouldBe(_source.X1);
}

[TestMethod]
public void UpdateObjectInsaiderToObject()
{
var _source = new InsaderObject() { X1 = 1 };
var _Destination = new InsaderObject() { X1 = new Object() };

var _result = _source.Adapt(_Destination);

_result.X1.ShouldBe(_source.X1);
}

[TestMethod]
public void UpdateObjectInsaiderWhenObjectinTSource()
{
var _source = new InsaderObject() { X1 = new Object() };
var _Destination = new InsaderObject() { X1 = 3 };

var _result = _source.Adapt(_Destination);

_result.X1.ShouldBe(_source.X1);
}


#region TestFunctions

Expand Down Expand Up @@ -112,6 +145,12 @@ class ManyDest524
public int X2 { get; set;}
}

class InsaderObject
{
public Object X1 { get; set;}
}


#endregion TestClasses
}
}
11 changes: 0 additions & 11 deletions src/Mapster/Adapters/ObjectAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,5 @@ protected override Expression CreateInlineExpression(Expression source, CompileA
{
return CreateInstantiationExpression(source, arg);
}

protected override Expression CreateExpressionBody(Expression source, Expression? destination, CompileArgument arg)
{
var srcType = arg.SourceType;
var destType = arg.DestinationType;

if (destination != null && srcType == typeof(object)) // Infinity Loop Breaker When Update use real instanse of Object _Object.Adapt(_TDestination);
return destination;

return base.CreateExpressionBody(source, destination, arg);
}
}
}

0 comments on commit e0ae818

Please sign in to comment.