Exemplo n.º 1
0
        /// <summary>
        /// 将 <see cref="DictionaryEntry"/> 中的键值表示为字符串。
        /// </summary>
        /// <param name="value">要表示为字符串的 <see cref="DictionaryEntry"/>。</param>
        /// <param name="represented">已经在路径中表示过的对象。</param>
        /// <returns>表示 <paramref name="value"/> 中的键值的字符串。</returns>
        protected override string RepresentCore(DictionaryEntry value, ISet <object> represented)
        {
            var keyRepresenter   = StructuralRepresenter.OfType(value.Key?.GetType());
            var valueRepresenter = StructuralRepresenter.OfType(value.Value?.GetType());
            var keyRepresent     = keyRepresenter.Represent(value.Key, represented);
            var valueRepresent   = valueRepresenter.Represent(value.Value, represented);

            return($"[{keyRepresent}] = {valueRepresent}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将指定数组中的元素表示为字符串。
        /// </summary>
        /// <param name="value">要表示为字符串的数组。</param>
        /// <param name="represented">已经在路径中访问过的对象。</param>
        /// <returns>表示 <paramref name="value"/> 中的元素的字符串。</returns>
        protected override string RepresentCore(TItem[] value, ISet <object> represented)
        {
            var represents = new List <string>();

            foreach (var item in value)
            {
                var representer = StructuralRepresenter.OfType(item?.GetType());
                represents.Add(representer.Represent(item, represented));
            }
            return($"{value.GetType().ToString()} {{ {string.Join(", ", represents)} }}");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 将指定对象中的公共实例成员表示为字符串。
        /// </summary>
        /// <param name="value">要表示为字符串的对象。</param>
        /// <param name="represented">已经在路径中访问过的对象。</param>
        /// <returns>表示 <paramref name="value"/> 中的成员的字符串。</returns>
        protected override string RepresentCore([DisallowNull] T value, ISet <object> represented)
        {
            var represents = this.GetPublicValues(value).Select(namedValue =>
            {
                var valueType   = namedValue.Value?.GetType();
                var representer = StructuralRepresenter.OfType(valueType);
                var represent   = representer.Represent(namedValue.Value, represented);
                return($"{namedValue.Key} = {represent}");
            });

            return($"{typeof(T).ToString()} {{ {string.Join(", ", represents)} }}");
        }
Exemplo n.º 4
0
 /// <summary>
 /// 将指定数组中指定索引处的元素表示为字符串。
 /// </summary>
 /// <param name="array">要将元素表示为字符串的数组。</param>
 /// <param name="indices">要表示为字符串的元素的索引。</param>
 /// <param name="represented">已经在路径中访问过的对象。</param>
 /// <returns>表示 <paramref name="array"/> 中索引为
 /// <paramref name="indices"/> 的元素的字符串。</returns>
 private string RepresentArray(Array array, int[] indices, ISet <object> represented)
 {
     if (indices.Length == array.Rank)
     {
         var item        = array.GetValue(indices);
         var representer = StructuralRepresenter.OfType(item?.GetType());
         return(representer.Represent(item, represented));
     }
     else
     {
         var represents = new List <string>();
         var length     = array.GetLength(indices.Length);
         for (int index = 0; index < length; index++)
         {
             var nextIndices = indices.Append(index);
             represents.Add(this.RepresentArray(array, nextIndices, represented));
         }
         return($"{{ {string.Join(", ", represents)} }}");
     }
 }