コード例 #1
0
 static void BuildDisplayName(StringBuilder sb, DiffMetadata property)
 {
     if (!property.IsCollectionItem)
     {
         sb.Append(property.DisplayName);
     }
     else
     {
         if (property.AfterIndex != null)
         {
             if (property.AfterIndex == property.BeforeIndex)
             {
                 sb.AppendFormat("[{0}]", property.AfterIndex + 1);
             }
             else
             {
                 if (property.BeforeIndex == null)
                 {
                     sb.AppendFormat("[{0}, added]", property.AfterIndex + 1);
                 }
                 else
                 {
                     sb.AppendFormat("[{0}, was {1}]", property.AfterIndex + 1, property.BeforeIndex + 1);
                 }
             }
         }
         else if (property.BeforeIndex != null)
         {
             sb.Append("[removed]");
         }
     }
 }
コード例 #2
0
        static void ReadableDiffInternal(StringBuilder sb, DiffMetadata diff)
        {
            var filteredProperties = diff
                                     .FlattenHierarchy <DiffMetadata, Tuple <Stack <DiffMetadata>, DiffMetadata> >(child => child.Properties.Concat(child.Items), (stack, child) => Tuple.Create(stack, child))
                                     .Where(ReadablePropertyFilter);

            var properties = filteredProperties.OrderBy(s => s, new DiffStackComparer());

            //.ThenBy(p => p.Item1.Count > 0 ? (int?) p.Item1.Peek().AfterIndex.GetValueOrDefault(int.MaxValue) : null)
            //.ThenBy(p => p.Item1.Count > 0 ? (int?) p.Item1.Peek().Order : null)
            //.ThenBy(p => p.Item1.Count > 0 ? p.Item1.Peek().DisplayName : null)
            //.ThenBy(p => p.Item2.AfterIndex.GetValueOrDefault(int.MaxValue))
            //.ThenBy(p => p.Item2.Order)
            //.ThenBy(p => p.Item2.DisplayName);

            foreach (var property in properties)
            {
                BuildDisplayName(sb, property);
                sb.Append(ReadablePropertyValueSeparator);

                if (!property.Item2.PropertyInBefore)
                {
                    OutputValue(sb, property.Item2.AfterFormattedValue);

                    if (sb[sb.Length - 1] != '\n')
                    {
                        sb.Append(", ");
                    }

                    sb.Append("was not present");
                }
                else if (!property.Item2.PropertyInAfter)
                {
                    sb.Append("No value present, was ");
                    OutputValue(sb, property.Item2.BeforeFormattedValue);
                }
                else
                {
                    if (property.Item2.AfterIndex != null || property.Item2.BeforeIndex == null)
                    {
                        OutputValue(sb, property.Item2.AfterFormattedValue);

                        if (property.Item2.AfterIndex == null || property.Item2.BeforeIndex != null)
                        {
                            if (sb[sb.Length - 1] != '\n')
                            {
                                sb.Append(", ");
                            }
                        }
                    }

                    if (property.Item2.AfterIndex == null || property.Item2.BeforeIndex != null)
                    {
                        sb.Append("was ");
                        OutputValue(sb, property.Item2.BeforeFormattedValue);
                    }
                }

                if (sb[sb.Length - 1] != '\n')
                {
                    sb.AppendLine();
                }
            }
        }