Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to Ignore() processing and Fix MapToTarget behavior for RecordTypes #769

Open
wants to merge 19 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactoring algorithm
  • Loading branch information
DocSvartz committed Jan 22, 2025
commit 0685bb31ad4175295292761fab993e78cf0db2b7
21 changes: 7 additions & 14 deletions src/Mapster/Adapters/BaseClassAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,18 @@ protected Expression CreateInstantiationExpression(Expression source, ClassMappi
getter = Expression.Condition(condition, getter, defaultConst);
}
else
if (arg.Settings.Ignore.Count != 0)
if (arg.Settings.Ignore.Any(x => x.Key == member.DestinationMember.Name))
{
if (arg.MapType != MapType.MapToTarget && arg.Settings.Ignore.Any(x => x.Key == member.DestinationMember.Name))
getter = defaultConst;
getter = defaultConst;

if (arg.MapType == MapType.MapToTarget && arg.DestinationType.IsRecordType())
{
if (arg.Settings.Ignore.Any(x => x.Key == member.DestinationMember.Name))
{
var find = arg.DestinationType.GetFieldsAndProperties(arg.Settings.EnableNonPublicMembers.GetValueOrDefault()).ToArray()
.Where(x => x.Name == member.DestinationMember.Name).FirstOrDefault();

if (find != null)
getter = Expression.MakeMemberAccess(destination, (MemberInfo)find.Info);
}
else
getter = defaultConst;
}
var find = arg.DestinationType.GetFieldsAndProperties(arg.Settings.EnableNonPublicMembers.GetValueOrDefault()).ToArray()
DocSvartz marked this conversation as resolved.
Show resolved Hide resolved
.Where(x => x.Name == member.DestinationMember.Name).FirstOrDefault();

if (find != null)
getter = Expression.MakeMemberAccess(destination, (MemberInfo)find.Info);
}
}
}
arguments.Add(getter);
Expand Down
Loading