private IEnumerable <PropertyDescriptor> FilterIgnoredProperties( IEnumerable <PropertyDescriptor> propertyDescriptors, object source, MixerSettings settings ) { foreach (var prop in propertyDescriptors) { var comparison = new Tuple <string, string>(source.GetType().Name, prop.Name); if (!settings.IgnoredProperties.Contains(comparison)) { yield return(prop); } } }
public static ExpandoObject MergeObjects(object left, object right) { _left = left; _right = right; var defaultSettings = new MixerSettings(); var props = GetPropertiesResultSet(_left, _right, defaultSettings); foreach (var prop in props) { AddProperty(_expando, prop.Key, prop.Value); } return(_expando); }
public ExpandoObject MixObjects(object left, object right, MixerSettings settings) { _left = left; _right = right; var props = GetPropertiesResultSet(_left, _right, settings); foreach (var prop in props) { AddProperty(_expando, prop.Key, prop.Value); } return(_expando); }
private static Dictionary <string, object> GetPropertiesResultSet(object left, object right, MixerSettings settings) { var leftDescriptors = GetPropDescriptorsArray(left); var rightDescriptors = GetPropDescriptorsArray(right); PropertyComparer <PropertyDescriptor> nameComparer = new PropertyComparer <PropertyDescriptor>(x => x.Name); var forComparisonDescr = leftDescriptors.Intersect <PropertyDescriptor>(rightDescriptors, nameComparer); var diffLeftDescr = leftDescriptors.Except <PropertyDescriptor>(rightDescriptors, nameComparer); var diffRightDescr = rightDescriptors.Except <PropertyDescriptor>(leftDescriptors, nameComparer); var resultSet = new Dictionary <string, object>(); foreach (var propertyDescriptor in diffLeftDescr) { resultSet.Add(propertyDescriptor.Name, propertyDescriptor.GetValue(left)); } foreach (var propertyDescriptor in diffRightDescr) { if (!resultSet.ContainsKey(propertyDescriptor.Name)) { resultSet.Add(propertyDescriptor.Name, propertyDescriptor.GetValue(right)); } } if (settings.Priority == Priority.Left) { PopulateComparedResultSetWithPriority(resultSet, forComparisonDescr, _left); } else if (settings.Priority == Priority.Right) { forComparisonDescr = rightDescriptors.Intersect <PropertyDescriptor>(leftDescriptors); PopulateComparedResultSetWithPriority(resultSet, forComparisonDescr, _right); } else if (settings.Priority == Priority.Merge) { PopulateComparedResultSetWithWerge(resultSet, forComparisonDescr); } return(resultSet); }