示例#1
0
        /// <summary>
        ///     Copies formatting-related property values from one verbose formatter to another one.
        ///     Use this method to change active formatter so that it formats string in the way
        ///     in which other formatter would do, but preserving other settings, like indentation details,
        ///     maximum depth when recursively iterating through contents of the object etc.
        /// </summary>
        /// <param name="src">Formatter from which formatting property values are copied.</param>
        /// <param name="dest">Formatter into which formatting property values are copied.</param>
        /// <returns>Reference to <paramref name="dest" /> which is the updated verbose formatter.</returns>
        public static VerboseFormatInfoBase CopyFormatting(VerboseFormatInfoBase src, VerboseFormatInfoBase dest)
        {
            dest.IsMultiLinedFormat             = src.IsMultiLinedFormat;
            dest.FieldDelimiter                 = src.FieldDelimiter;
            dest.LinePrefix                     = src.LinePrefix;
            dest.IndentationString              = src.IndentationString;
            dest.RightMostIndentationString     = src.RightMostIndentationString;
            dest.LastIndentationString          = src.LastIndentationString;
            dest.LastRightMostIndentationString = src.LastRightMostIndentationString;

            return(dest);
        }
示例#2
0
        /// <summary>
        ///     Tries to append character to the string builder within given amount of characters allowed. Always succeeds in multi-lined formatters.
        /// </summary>
        /// <param name="formatter">Formatter which has requested character to be appended.</param>
        /// <param name="sb">String builder to which string should be appended.</param>
        /// <param name="c">Character which should be appended.</param>
        /// <param name="success">
        ///     Indicates whether appending operations this far have been successful (true)
        ///     or some of the previous append operations has already failed (false). If false, appending will not be attempted.
        /// </param>
        /// <param name="maxLength">
        ///     On input contains maximum number of characters that are allowed to be appended to the string builder.
        ///     On output indicates remaining character positions allowed before appending will fail.
        /// </param>
        /// <returns>true if appending operation was successful within given number of allowed characters; otherwise false.</returns>
        public static bool TryAppendChar(VerboseFormatInfoBase formatter, StringBuilder sb, char c, bool success, ref int maxLength)
        {
            if (success && (formatter.IsMultiLinedFormat || maxLength < 0 || maxLength > 0))
            {
                sb.Append(c);
                if (maxLength > 0)
                {
                    maxLength--;
                }
            }
            else
            {
                success = false;
            }

            return(success);
        }
示例#3
0
        /// <summary>
        ///     Copy constructor. Used to build format providers that share common property values with some existing instance.
        /// </summary>
        /// <param name="other">Instance from which common property values will be copied.</param>
        public VerboseFormatInfoBase(VerboseFormatInfoBase other)
            : this()
        {
            _instanceDataType = other._instanceDataType;
            _instanceName     = other._instanceName;
            _fieldDelimiter   = other._fieldDelimiter;

            _firstContainedValuePrefix = other._firstContainedValuePrefix;
            _lastContainedValueSuffix  = other._lastContainedValueSuffix;

            _isMultiLinedFormat = other._isMultiLinedFormat;
            _linePrefix         = other._linePrefix;

            _indentationString              = other._indentationString;
            _rightMostIndentationString     = other._rightMostIndentationString;
            _lastIndentationString          = other._lastIndentationString;
            _lastRightMostIndentationString = other._lastRightMostIndentationString;

            _maximumDepth           = other._maximumDepth;
            _maximumFormattedLength = other._maximumFormattedLength;

            _showDataType     = other._showDataType;
            _showInstanceName = other._showInstanceName;

            while (_indentationLevel < other.IndentationLevel)
            {
                IncIndentationLevel(other.IsIndentationLevelOccupied(_indentationLevel + 1));
            }

            if (other._visitedInstances != null && other._visitedInstances.Count > 0)
            {
                var tempStack = new Stack <object>();
                foreach (var obj in other._visitedInstances)
                {
                    tempStack.Push(obj);
                }

                _visitedInstances = new Stack <object>();
                while (tempStack.Count > 0)
                {
                    _visitedInstances.Push(tempStack.Pop());
                }
            }
        }
示例#4
0
        /// <summary>
        ///     Tries to append single white space if string builder doesn't end with space or new line character.
        ///     Use this method to separate successive items appended to string builder.
        /// </summary>
        /// <param name="formatter">Formatter which has requested character to be appended.</param>
        /// <param name="sb">String builder to which whitespace is appended.</param>
        /// <param name="success">
        ///     Indicates whether appending operations this far have been successful (true)
        ///     or some of the previous append operations has already failed (false). If false, appending will not be attempted.
        /// </param>
        /// <param name="maxLength">
        ///     Maximum number of characters allowed to the formatter. Formatting will fail (and return false)
        ///     if this number of characters is breached. Multi-lined formatters will ignore this parameter.
        ///     Negative value indicates that formatter has unlimited space available. On output contains remaining number of characters available.
        /// </param>
        /// <returns>
        ///     true if space has been successfully appended to <paramref name="sb" /> within given number of allowed characters
        ///     or there was no need to append space; otherwise false.
        /// </returns>
        public static bool TryAppendSpaceIfNeeded(VerboseFormatInfoBase formatter, StringBuilder sb, bool success, ref int maxLength)
        {
            if (success)
            {
                var originalLength = sb.Length;

                var c = (sb.Length > 0 ? sb[sb.Length - 1] : '\0');
                if (c != '\r' && c != '\n' && c != ' ' && c != '\t')
                {
                    success = TryAppendChar(formatter, sb, ' ', success, ref maxLength);
                }

                if (!success)
                {
                    sb.Length = originalLength;
                }
            }

            return(success);
        }
示例#5
0
        /// <summary>
        ///     Tries to append string to the string builder within given amount of characters allowed. Always succeeds in multi-lined formatters.
        /// </summary>
        /// <param name="formatter">Formatter which has requested character to be appended.</param>
        /// <param name="sb">String builder to which string should be appended.</param>
        /// <param name="s">String which should be appended.</param>
        /// <param name="success">
        ///     Indicates whether appending operations this far have been successful (true)
        ///     or some of the previous append operations has already failed (false). If false, appending will not be attempted.
        /// </param>
        /// <param name="maxLength">
        ///     On input contains maximum number of characters that are allowed to be appended to the string builder.
        ///     On output indicates remaining character positions allowed before appending will fail.
        /// </param>
        /// <returns>
        ///     true if appending operation was successful, i.e. allowed number of characters
        ///     has not been breached; otherwise false.
        /// </returns>
        public static bool TryAppendString(VerboseFormatInfoBase formatter, StringBuilder sb, string s, bool success, ref int maxLength)
        {
            if (s == null)
            {
                s = string.Empty;
            }

            if (success && (formatter.IsMultiLinedFormat || maxLength < 0 || maxLength >= s.Length))
            {
                sb.Append(s);
                if (maxLength > 0)
                {
                    maxLength -= s.Length;
                }
            }
            else
            {
                success = false;
            }

            return(success);
        }
示例#6
0
 /// <summary>
 ///     Copy constructor which uses other instance to copy values that are common to all verbose format providers.
 /// </summary>
 /// <param name="other">Object from which common values will be copied.</param>
 public CompactMatrixFormatInfo(VerboseFormatInfoBase other)
     : base(other)
 {
 }
示例#7
0
 /// <summary>
 ///     Copy constructor. Used to copy only those property values that are common to all classes derived from VerboseFormatInfoBase.
 /// </summary>
 /// <param name="other">Instance from which contents is copied to new instance of this class.</param>
 public VerboseFormatInfo(VerboseFormatInfoBase other)
     : base(other)
 {
 }
 /// <summary>
 ///     Copy constructor which uses other instance to copy internal values which are common to all verbose formatters.
 /// </summary>
 /// <param name="other">Instance from which values are copied that are common to all verbose formatters.</param>
 public EnumerableFormatInfo(VerboseFormatInfoBase other)
     : base(other)
 {
 }
 /// <summary>
 ///     Copy constructor which creates new instance having same values of common properties as other instance.
 /// </summary>
 /// <param name="other">Instance from which values are taken for common properties.</param>
 public DictionaryFormatInfo(VerboseFormatInfoBase other)
     : base(other)
 {
 }
示例#10
0
 /// <summary>
 ///     Copy constructor which copies values common to all verbose format providers.
 /// </summary>
 /// <param name="other">Instance from which common values are copied.</param>
 public GeneralFormatInfo(VerboseFormatInfoBase other)
     : base(other)
 {
 }