protected override Expression GetTargetObjectCreation(IObjectMappingData mappingData, IList <Expression> memberPopulations) { var objectCreation = base.GetTargetObjectCreation(mappingData, memberPopulations); if (objectCreation == null) { memberPopulations.Clear(); } if (memberPopulations.None()) { return(objectCreation); } var memberBindings = GetMemberBindingsFrom(memberPopulations); if (memberBindings.None()) { return(objectCreation); } var objectNewings = NewExpressionFinder.FindIn(objectCreation); var newingReplacements = new Dictionary <Expression, Expression>(objectNewings.Count); foreach (var objectNewing in objectNewings) { var objectInit = Expression.MemberInit(objectNewing, memberBindings); newingReplacements.Add(objectNewing, objectInit); } var fullObjectInit = objectCreation.Replace(newingReplacements); return(fullObjectInit); }
public static ICollection <NewExpression> FindIn(Expression objectCreation) { var finder = new NewExpressionFinder(); finder.Visit(objectCreation); return(finder._newings); }