コード例 #1
0
 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);
         }
     }
 }
コード例 #2
0
ファイル: ObjectMixer.cs プロジェクト: oiOne/ObjectsMixer
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: ObjectMixer.cs プロジェクト: oiOne/ObjectsMixer
        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);
        }