Esempio n. 1
0
        /// <summary>
        ///     Return a string that gives detailed information of the state of the given List of Sockets,
        ///     for debugging purposes.
        /// </summary>
        /// <param name="list">the List of Sockets to describe</param>
        /// <returns>a string detailing the list contents, including the state of each Socket</returns>
        /// <remarks>
        ///     This is intended just for debugging purposes, as when adding detailed information to the Message of an
        ///     exception when an error occurs. In DEBUG mode more detail is provided.
        /// </remarks>
        public static string AsString(List <Socket> list)
        {
            StringBuilder sb = new StringBuilder();

            if (list == null)
            {
                sb.Append("(null)");
            }
            else
            {
                int n = list.Count;
                if (n == 0)
                {
                    sb.Append("(empty list)");
                }
                else
                {
                    if (n == 1)
                    {
                        sb.Append("List<Socket> with 1 Socket: ");
                        sb.Append(list[0].AsString());
                    }
                    else
                    {
                        sb.Append("List with ").Append(n).Append(" Sockets: ");

                        for (int i = 0; i < n; i++)
                        {
                            Socket socket = list[i];
                            string s      = socket.AsString();
                            sb.Append(s);
                            if (i < n - 1)
                            {
                                sb.Append(", ");
                            }
                        }
                    }
                }
            }

            return(sb.ToString());
        }