Exemple #1
0
        /// <summary>
        /// Returns a human-readable representation of a particular object.
        /// </summary>
        /// <param name="value">The value for which to create a <see cref="System.String"/>.</param>
        /// <param name="nestedPropertyLevel">
        ///     The level of nesting for the supplied value. This is used for indenting the format string for objects that have
        ///     no <see cref="object.ToString()"/> override.
        /// </param>
        /// <param name="useLineBreaks">
        /// Indicates whether the formatter should use line breaks when the specific <see cref="IValueFormatter"/> supports it.
        /// </param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public static string ToString(object value, bool useLineBreaks = false, IList <object> processedObjects = null, int nestedPropertyLevel = 0)
        {
            if (processedObjects == null)
            {
                processedObjects = new List <object>();
            }

            IValueFormatter firstFormatterThatCanHandleValue = Formatters.First(f => f.CanHandle(value));

            return(firstFormatterThatCanHandleValue.ToString(value, useLineBreaks, processedObjects, nestedPropertyLevel));
        }
        /// <summary>
        /// Returns a human-readable representation of a particular object.
        /// </summary>
        /// <param name="value">The value for which to create a <see cref="System.String"/>.</param>
        /// <param name="nestedPropertyLevel">
        ///     The level of nesting for the supplied value. This is used for indenting the format string for objects that have
        ///     no <see cref="object.ToString()"/> override.
        /// </param>
        /// <param name="useLineBreaks">
        /// Indicates whether the formatter should use line breaks when the specific <see cref="IValueFormatter"/> supports it.
        /// </param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public static string ToString(object value, bool useLineBreaks = false, IList <object> processedObjects = null, int nestedPropertyLevel = 0)
        {
            if (processedObjects == null)
            {
                processedObjects = new List <object>();
            }

            const int MaxDepth = 15;

            if (nestedPropertyLevel > MaxDepth)
            {
                return("{Maximum recursion depth was reached...}");
            }

            IValueFormatter firstFormatterThatCanHandleValue = Formatters.First(f => f.CanHandle(value));

            return(firstFormatterThatCanHandleValue.ToString(value, useLineBreaks, processedObjects, nestedPropertyLevel));
        }