Пример #1
0
        /// <summary>
        /// Gets a string that represents the setting.
        /// </summary>
        ///
        /// <param name="includeComment">Specify true to include the comments in the string; false otherwise.</param>
        public string ToString(bool includeComment)
        {
            if (includeComment)
            {
                bool hasPreComments = mPreComments != null && mPreComments.Count > 0;

                string[] preCommentStrings = hasPreComments ?
                                             mPreComments.ConvertAll(c => c.ToString()).ToArray() : null;

                if (Comment != null && hasPreComments)
                {
                    // Include inline comment and pre-comments.
                    return(string.Format("{0}\n{1}={2} {3}",
                                         string.Join(Environment.NewLine, preCommentStrings),
                                         Name, mRawValue, Comment.ToString()));
                }
                else if (Comment != null)
                {
                    // Include only the inline comment.
                    return(string.Format("{0}={1} {2}", Name, mRawValue, Comment.ToString()));
                }
                else if (hasPreComments)
                {
                    // Include only the pre-comments.
                    return(string.Format("{0}\n{1}={2}",
                                         string.Join(Environment.NewLine, preCommentStrings),
                                         Name, mRawValue));
                }
            }

            // In every other case, include just the assignment in the string.
            return(string.Format("{0}={1}", Name, mRawValue));
        }
Пример #2
0
        /// <summary>
        /// Convert this object into a string representation.
        /// </summary>
        ///
        /// <param name="includeComment">True to include, false to exclude the comment.</param>
        ///
        /// <returns>
        /// A string that represents the current object.
        /// </returns>
        public string ToString(bool includeComment)
        {
            if (includeComment)
            {
                bool hasPreComments = mPreComments != null && mPreComments.Count > 0;

                string[] preCommentStrings = hasPreComments ?
                                             mPreComments.ConvertAll <string>(Comment.ConvertToString).ToArray() : null;

                if (Comment != null && hasPreComments)
                {
                    // Include inline comment and pre-comments.
                    return(string.Format("{0}\n[{1}] {2}",
                                         string.Join(Environment.NewLine, preCommentStrings),
                                         Name, Comment.ToString()));
                }
                else if (Comment != null)
                {
                    // Include only the inline comment.
                    return(string.Format("[{0}] {1}", Name, Comment.ToString()));
                }
                else if (hasPreComments)
                {
                    // Include only the pre-comments.
                    return(string.Format("{0}\n[{1}]",
                                         string.Join(Environment.NewLine, preCommentStrings),
                                         Name));
                }
            }

            return(string.Format("[{0}]", Name));
        }
Пример #3
0
        /// <summary>
        /// Gets the string representation of the section.
        /// </summary>
        ///
        /// <param name="includeComment">True to include, false to exclude the comment.</param>
        public string ToString(bool includeComment)
        {
            if (includeComment)
            {
                bool hasPreComments = mPreComments != null && mPreComments.Count > 0;

                string[] preCommentStrings = hasPreComments ?
                                             mPreComments.Select(c => c.ToString()).ToArray() : null;

                if (Comment != null && hasPreComments)
                {
                    // Include inline comment and pre-comments.
                    return(string.Format("{0}{1}[{2}] {3}",
                                         string.Join(Environment.NewLine, preCommentStrings), // {0}
                                         Environment.NewLine,                                 // {1}
                                         Name,                                                // {2}
                                         Comment.ToString()                                   // {3}
                                         ));
                }
                else if (Comment != null)
                {
                    // Include only the inline comment.
                    return(string.Format("[{0}] {1}", Name, Comment.ToString()));
                }
                else if (hasPreComments)
                {
                    // Include only the pre-comments.
                    return(string.Format("{0}{1}[{2}]",
                                         string.Join(Environment.NewLine, preCommentStrings), // {0}
                                         Environment.NewLine,                                 // {1}
                                         Name                                                 // {2}
                                         ));
                }
            }

            return(string.Format("[{0}]", Name));
        }
Пример #4
0
 // Used by Setting and Section in ToString().
 internal static string ConvertToString(Comment comment)
 {
     return comment.ToString();
 }
Пример #5
0
 // Used by Setting and Section in ToString().
 internal static string ConvertToString(Comment comment)
 {
     return(comment.ToString());
 }