/// <summary>
        /// add comments to a block represented by string arrays
        /// </summary>
        /// <param name="lines">array of strings to be commented</param>
        /// <param name="type">type of comment to be added</param>
        /// <param name="position">Where to add the comments</param>
        /// <returns></returns>
        public static void Comment(this string[] lines, CommentType type, CommentPosition position = CommentPosition.Front)
        {
            string commentstringFront = "";
            string commentstringBack  = "";

            if (position == CommentPosition.Front)
            {
                switch (type)
                {
                case CommentType.HashCharComments:
                    commentstringFront = "# ";
                    break;

                case CommentType.TraditionalC:
                    commentstringFront = "/* ";
                    commentstringBack  = " */";
                    break;

                case CommentType.Cplusplus:     // implicitly front and back
                    commentstringFront = "// ";
                    break;
                }
            }
            else
            {
                switch (type)
                {
                case CommentType.HashCharComments:
                    commentstringBack = " #";
                    break;

                case CommentType.TraditionalC:
                    commentstringFront = "/* ";
                    commentstringBack  = " */";
                    break;


                case CommentType.Cplusplus:     // implicitly front and back
                    commentstringBack = " //";
                    break;
                }
            }

            Comment(lines, commentstringFront, commentstringBack);
        }
Пример #2
0
        /// <summary>
        /// Add comment to a statement.
        /// </summary>
        /// <param name="statementSyntax">Statement</param>
        /// <param name="comment">Comment text</param>
        /// <param name="commentPosition">The position of the comment.</param>
        /// <returns>Statement with comment.</returns>
        public static StatementSyntax WithComment(this StatementSyntax statementSyntax, string comment, CommentPosition commentPosition = CommentPosition.Above)
        {
            switch (commentPosition)
            {
            case CommentPosition.Above:
                return(statementSyntax.WithLeadingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.Comment($"//{comment}\n"))));

            case CommentPosition.Right:
                return(statementSyntax.WithTrailingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.Comment($" //{comment}\n"))));

            default:
                throw new ArgumentOutOfRangeException(nameof(commentPosition), commentPosition, null);
            }
        }
Пример #3
0
		/// <summary>
		/// Initializes a comment.
		/// </summary>
		/// <param name="type">Type of this comment.</param>
		/// <param name="position">Position of this comment.</param>
		/// <param name="content">Content text of this comment.</param>
		public Comment(CommentType type, CommentPosition position, string content)
		{
			this.type = type;
			this.position = position;
			this.content = content;
		}