Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stringbuilder"></param>
 /// <param name="formatProvider"></param>
 /// <param name="rest"></param>
 /// <returns></returns>
 public bool Show(System.Text.StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
 {
     if (rest < 0)
     {
         return(false);
     }
     if (!Showing.Show(Key, stringbuilder, ref rest, formatProvider))
     {
         return(false);
     }
     stringbuilder.Append(" => ");
     rest -= 4;
     if (!Showing.Show(Value, stringbuilder, ref rest, formatProvider))
     {
         return(false);
     }
     return(rest >= 0);
 }
Esempio n. 2
0
 public bool Show(StringBuilder sb, ref int rest, IFormatProvider formatProvider)
 {
     if (rest < 0)
     {
         return(false);
     }
     if (!Showing.Show(_value, sb, ref rest, formatProvider))
     {
         return(false);
     }
     sb.Append(" => ");
     rest -= 4;
     if (!Showing.Show(_count, sb, ref rest, formatProvider))
     {
         return(false);
     }
     return(rest >= 0);
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        ///
        /// <param name="dictionary"></param>
        /// <param name="stringbuilder"></param>
        /// <param name="formatProvider"></param>
        /// <param name="rest"></param>
        /// <returns></returns>
        public static bool ShowDictionary <K, V>(IDictionary <K, V> dictionary, StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
        {
            bool sorted = dictionary is ISortedDictionary <K, V>;

            stringbuilder.Append(sorted ? "[ " : "{ ");
            rest -= 4;                 // Account for "( " and " )"
            bool first    = true;
            bool complete = true;

            {
                // foreach(var p in dictionary)
                var __enumerator3 = (dictionary).GetEnumerator();
                while (__enumerator3.MoveNext())
                {
                    var p = (KeyValuePair <K, V>)__enumerator3.Current;
                    {
                        complete = false;
                        if (rest <= 0)
                        {
                            break;
                        }
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            stringbuilder.Append(", ");
                            rest -= 2;
                        }
                        complete = Showing.Show(p, stringbuilder, ref rest, formatProvider);
                    }
                }
            }
            if (!complete)
            {
                stringbuilder.Append("...");
                rest -= 3;
            }
            stringbuilder.Append(sorted ? " ]" : " }");
            return(complete);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        ///
        /// <param name="dictionary"></param>
        /// <param name="stringbuilder"></param>
        /// <param name="formatProvider"></param>
        /// <param name="rest"></param>
        /// <returns></returns>
        public static bool ShowDictionary <K, V>(IDictionary <K, V> dictionary, StringBuilder stringbuilder, ref int rest, IFormatProvider?formatProvider)
        {
            bool sorted = dictionary is ISortedDictionary <K, V>;

            stringbuilder.Append(sorted ? "[ " : "{ ");
            rest -= 4;                             // Account for "( " and " )"
            bool first    = true;
            bool complete = true;

            foreach (System.Collections.Generic.KeyValuePair <K, V> p in dictionary)
            {
                complete = false;
                if (rest <= 0)
                {
                    break;
                }

                if (first)
                {
                    first = false;
                }
                else
                {
                    stringbuilder.Append(", ");
                    rest -= 2;
                }
                complete = Showing.Show(p, stringbuilder, ref rest, formatProvider);
            }
            if (!complete)
            {
                stringbuilder.Append("...");
                rest -= 3;
            }
            stringbuilder.Append(sorted ? " ]" : " }");
            return(complete);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="stringbuilder"></param>
        /// <param name="rest"></param>
        /// <param name="formatProvider"></param>
        /// <returns>True if collection was shown completely</returns>
        public static bool ShowCollectionValue <T>(ICollectionValue <T> items, StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
        {
            string startdelim = "{ ", enddelim = " }";
            bool   showIndexes        = false;
            bool   showMultiplicities = false;
            //TODO: do not test here at run time, but select code at compile time
            //      perhaps by delivering the print type to this metod
            IList <T>       list;
            ICollection <T> coll = items as ICollection <T>;

            if ((list = items as IList <T>) != null)
            {
                startdelim = "[ ";
                enddelim   = " ]";
                //TODO: should have been (items as IIndexed<T>).IndexingSpeed
                showIndexes = list.IndexingSpeed == Speed.Constant;
            }
            else if (coll != null)
            {
                if (coll.AllowsDuplicates)
                {
                    startdelim = "{{ ";
                    enddelim   = " }}";
                    if (coll.DuplicatesByCounting)
                    {
                        showMultiplicities = true;
                    }
                }
            }

            stringbuilder.Append(startdelim);
            rest -= 2 * startdelim.Length;
            bool first    = true;
            bool complete = true;
            int  index    = 0;

            if (showMultiplicities)
            {
                foreach (KeyValuePair <T, int> p in coll.ItemMultiplicities())
                {
                    complete = false;
                    if (rest <= 0)
                    {
                        break;
                    }
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        stringbuilder.Append(", ");
                        rest -= 2;
                    }
                    if (complete = Showing.Show(p.Key, stringbuilder, ref rest, formatProvider))
                    {
                        string multiplicityString = string.Format("(*{0})", p.Value);
                        stringbuilder.Append(multiplicityString);
                        rest -= multiplicityString.Length;
                    }
                }
            }
            else
            {
                foreach (T x in items)
                {
                    complete = false;
                    if (rest <= 0)
                    {
                        break;
                    }
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        stringbuilder.Append(", ");
                        rest -= 2;
                    }
                    if (showIndexes)
                    {
                        string indexString = string.Format("{0}:", index++);
                        stringbuilder.Append(indexString);
                        rest -= indexString.Length;
                    }
                    complete = Showing.Show(x, stringbuilder, ref rest, formatProvider);
                }
            }
            if (!complete)
            {
                stringbuilder.Append("...");
                rest -= 3;
            }
            stringbuilder.Append(enddelim);
            return(complete);
        }
Esempio n. 6
0
 public string ToString(string format, IFormatProvider formatProvider)
 {
     return(Showing.ShowString(this, format, formatProvider));
 }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stringbuilder"></param>
 /// <param name="rest"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public override bool Show(System.Text.StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
 {
     return(Showing.ShowDictionary <K, V>(this, stringbuilder, ref rest, formatProvider));
 }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stringbuilder"></param>
 /// <param name="rest"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public virtual bool Show(System.Text.StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
 {
     return(Showing.ShowCollectionValue <T>(this, stringbuilder, ref rest, formatProvider));
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="format"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public virtual string ToString(string?format, IFormatProvider?formatProvider)
 {
     return(Showing.ShowString(this, format, formatProvider));
 }