Add() public method

public Add ( CodeCommentStatement value ) : int
value CodeCommentStatement
return int
Beispiel #1
0
 /// <summary>
 /// Add to CodeCommentStatementCollection summary documentation
 /// </summary>
 /// <param name="codeStatmentColl">Collection of CodeCommentStatement</param>
 /// <param name="comment">summary text</param>
 internal static void CreateSummaryComment(CodeCommentStatementCollection codeStatmentColl, string comment)
 {
     codeStatmentColl.Add(new CodeCommentStatement("<summary>", true));
     string[] lines = comment.Split(new[] { '\n' });
     foreach (string line in lines)
         codeStatmentColl.Add(new CodeCommentStatement(line.Trim(), true));
     codeStatmentColl.Add(new CodeCommentStatement("</summary>", true));
 }
Beispiel #2
0
 public static CodeCommentStatementCollection Clone(CodeCommentStatementCollection codestatementcol)
 {
     var col = new CodeCommentStatementCollection();
     foreach(CodeCommentStatement cstat in codestatementcol) {
         col.Add(Clone(cstat));
     }
     return col;
 }
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeCommentStatementCollection coll = new CodeCommentStatementCollection (array);
			coll.CopyTo (array, 0);
			Assert.AreEqual (1, coll.Add (ccs), "Add");
			Assert.AreSame (ccs, coll[0], "this[int]");
			coll.AddRange (array);
			coll.AddRange (coll);
			Assert.IsTrue (coll.Contains (ccs), "Contains");
			Assert.AreEqual (0, coll.IndexOf (ccs), "IndexOf");
			coll.Insert (0, ccs);
			coll.Remove (ccs);
		}
 internal static void AddWarningComment(CodeCommentStatementCollection comments, string text) {
     Debug.Assert(comments != null);
     comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlCodegenWarningDetails, text), false));
 }
Beispiel #5
0
        /// <summary>
        /// emit documentation comments between xml open and close tags
        /// </summary>
        /// <param name="tag">the xml tag name</param>
        /// <param name="summaryComments">the lines of comments to emit</param>
        /// <param name="commentCollection">the comment collection of the CodeDom object to be commented</param>
        private static void EmitXmlComments(string tag, string[] summaryComments, CodeCommentStatementCollection commentCollection)
        {
            Debug.Assert(tag != null);
            Debug.Assert(summaryComments != null);
            Debug.Assert(commentCollection != null);

            commentCollection.Add(new CodeCommentStatement(string.Format(CultureInfo.InvariantCulture, "<{0}>", tag), true));
            EmitComments(summaryComments, commentCollection, true);
            commentCollection.Add(new CodeCommentStatement(string.Format(CultureInfo.InvariantCulture, "</{0}>", tag), true));
        }
Beispiel #6
0
        /// <summary>
        /// Emit some lines of comments
        /// </summary>
        /// <param name="commentLines">the lines of comments to emit</param>
        /// <param name="commentCollection">the comment collection of the CodeDom object to be commented</param>
        /// <param name="docComment">true if the comments are 'documentation' comments</param>
        public static void EmitComments(string[] commentLines, CodeCommentStatementCollection commentCollection, bool docComment)
        {
            Debug.Assert(commentLines != null, "commentLines parameter is null");
            Debug.Assert(commentCollection != null, "commentCollection parameter is null");

            foreach (string comment in commentLines)
            {
                commentCollection.Add(new CodeCommentStatement(comment, docComment));
            }
        }
		public void Remove ()
		{
			CodeCommentStatement ccs1 = new CodeCommentStatement ();
			CodeCommentStatement ccs2 = new CodeCommentStatement ();

			CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
			coll.Add (ccs1);
			coll.Add (ccs2);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
			coll.Remove (ccs1);
			Assert.AreEqual (1, coll.Count, "#4");
			Assert.AreEqual (-1, coll.IndexOf (ccs1), "#5");
			Assert.AreEqual (0, coll.IndexOf (ccs2), "#6");
		}
		public void AddRange ()
		{
			CodeCommentStatement ccs1 = new CodeCommentStatement ();
			CodeCommentStatement ccs2 = new CodeCommentStatement ();
			CodeCommentStatement ccs3 = new CodeCommentStatement ();

			CodeCommentStatementCollection coll1 = new CodeCommentStatementCollection ();
			coll1.Add (ccs1);
			coll1.Add (ccs2);

			CodeCommentStatementCollection coll2 = new CodeCommentStatementCollection ();
			coll2.Add (ccs3);
			coll2.AddRange (coll1);
			Assert.AreEqual (3, coll2.Count, "#1");
			Assert.AreEqual (1, coll2.IndexOf (ccs1), "#2");
			Assert.AreEqual (2, coll2.IndexOf (ccs2), "#3");
			Assert.AreEqual (0, coll2.IndexOf (ccs3), "#4");

			CodeCommentStatementCollection coll3 = new CodeCommentStatementCollection ();
			coll3.Add (ccs3);
			coll3.AddRange (new CodeCommentStatement[] { ccs1, ccs2 });
			Assert.AreEqual (3, coll2.Count, "#5");
			Assert.AreEqual (1, coll2.IndexOf (ccs1), "#6");
			Assert.AreEqual (2, coll2.IndexOf (ccs2), "#7");
			Assert.AreEqual (0, coll2.IndexOf (ccs3), "#8");
		}
        private CodeCommentStatementCollection InsertDocumentation(Documetation type, string[] text)
        {
            CodeCommentStatementCollection comments = new CodeCommentStatementCollection();

            switch (type)
            {
                case Documetation.Remarks:
                    comments.Add(new CodeCommentStatement("<remarks>", true));
                    break;
                case Documetation.Summary:
                    comments.Add(new CodeCommentStatement("<summary>", true));
                    break;
                case Documetation.Example:
                    comments.Add(new CodeCommentStatement("<example>", true));
                    break;
                case Documetation.Exception:
                    comments.Add(new CodeCommentStatement("<exception>", true));
                    break;
                case Documetation.Param:
                    comments.Add(new CodeCommentStatement("<param>", true));
                    break;
                case Documetation.Permission:
                    comments.Add(new CodeCommentStatement("<permission>", true));
                    break;
                case Documetation.Returns:
                    comments.Add(new CodeCommentStatement("<returns>", true));
                    break;
                case Documetation.SeeAlso:
                    foreach (string comment in text)
                        comments.Add(new CodeCommentStatement("<seealso cref=\"" + comment + "\" />", true));
                    return comments;
                case Documetation.Include:
                    comments.Add(new CodeCommentStatement("<include>", true));
                    break;
                default:
                    break;
            }

            foreach (string comment in text)
                comments.Add(new CodeCommentStatement(comment, (null != type)));

            switch (type)
            {
                case Documetation.Remarks:
                    comments.Add(new CodeCommentStatement("</remarks>", true));
                    break;
                case Documetation.Summary:
                    comments.Add(new CodeCommentStatement("</summary>", true));
                    break;
                case Documetation.Example:
                    comments.Add(new CodeCommentStatement("</example>", true));
                    break;
                case Documetation.Exception:
                    comments.Add(new CodeCommentStatement("</exception>", true));
                    break;
                case Documetation.Param:
                    comments.Add(new CodeCommentStatement("</param>", true));
                    break;
                case Documetation.Permission:
                    comments.Add(new CodeCommentStatement("</permission>", true));
                    break;
                case Documetation.Returns:
                    comments.Add(new CodeCommentStatement("</returns>", true));
                    break;
                case Documetation.Include:
                    comments.Add(new CodeCommentStatement("</include>", true));
                    break;
                default:
                    break;
            }

            return comments;
        }
Beispiel #10
0
 private static CodeCommentStatementCollection SplitCommentLines(string comment)
 {
     var lines = Regex.Split(comment, "[\r\n]+");
     var result = new CodeCommentStatementCollection();
     lines.ToList<String>().ConvertAll(c => new CodeCommentStatement(c, true)).ForEach(c => result.Add(c));
     return result;
 }
Beispiel #11
0
 private static void CreateCommentsAndObjectsForFunctionArguments(CodeMemberField member, XElement elm)
 {
     var args = elm.Elements("argument").ToList<XElement>();
     member.Comments.Add(new CodeCommentStatement("<br/>The signature of this function needs to be as follows:<br/>", true));
     var comment = "Function(";
     var idx = 0;
     var descriptions = new CodeCommentStatementCollection();
     descriptions.Add(new CodeCommentStatement("<ul>", true));
     var references = new CodeCommentStatementCollection();
     foreach (var arg in args)
     {
         if (idx++ > 0)
         {
             comment += ", ";
         }
         var type = "";
         if ((arg.Attribute("type").Value == "PlainObject") && (arg.Elements("property").Count() > 0))
         {
             type = CreateTypedObjectForPlainObject(arg.Attribute("name").Value, arg);
             references.Add(new CodeCommentStatement("@see randori.jquery." + type, true));
         }
         else
         {
             type = TranslateType(arg.Attribute("type").Value);
         }
         comment += arg.Attribute("name").Value + ":" + type;
         descriptions.Add(new CodeCommentStatement("<li>" + arg.Attribute("name").Value + ":" + type + " - " + arg.Element("desc").Value + "<li/>", true));
     }
     descriptions.Add(new CodeCommentStatement("</ul>", true));
     comment += "):void;";
     member.Comments.Add(new CodeCommentStatement(comment, true));
     member.Comments.AddRange(descriptions);
     ((CodeCommentStatementCollection)member.UserData["references"]).AddRange(references);
 }
		public static string GenerateErrorString(Exception ex, CodeDomProvider codeProvider, string fileName, string baseNamespace)
		{
			CodeGeneratorOptions gen = new CodeGeneratorOptions();
			gen.BracingStyle = "C";
			gen.IndentString = "\t";
			gen.VerbatimOrder = true;
			gen.BlankLinesBetweenMembers = false;

			CodeCommentStatementCollection comments = new CodeCommentStatementCollection();
			GenerateHeader(comments, fileName, baseNamespace);

			if (ex is CompileException)
			{
				CompileException cx = (CompileException)ex;
				comments.Add(new CodeCommentStatement(string.Format("Error generating shader:{0}{1} (line: {2} col: {3})", Environment.NewLine, cx.Text, cx.Line, cx.Coloumn)));
			}
			else if (ex is CompileExceptionCollection)
			{
				CompileExceptionCollection cxc = (CompileExceptionCollection)ex;
				for (int i = 0; i < cxc.Count; i++)
				{
					CompileException cx = cxc.GetException(i);
					comments.Add(new CodeCommentStatement(string.Format("Error generating shader:{0}{1} (line: {2} col: {3})", Environment.NewLine, cx.Text, cx.Line, cx.Coloumn)));
				}
			}
			else
			{
				comments.Add(new CodeCommentStatement(string.Format("Unhandled exception in XenFX:{0}{1}", Environment.NewLine, ex.ToString())));
			}
			
			StringBuilder sb = new StringBuilder();
			using (TextWriter writer = new StringWriter(sb))
			{
				foreach (CodeCommentStatement comment in comments)
				{
					codeProvider.GenerateCodeFromStatement(comment, writer, gen);
				}
			}
			return sb.ToString();
		}
 protected void Rewrite(CodeCommentStatementCollection target, CodeCommentStatementCollection source, ref bool didRewrite)
 {
     foreach (CodeCommentStatement item in source)
     {
         target.Add(this.Rewrite(item, ref didRewrite));
     }
 }
        /// <summary>
        /// Generates a summary comment.
        /// </summary>
        /// <param name="comments">Comments collection to add the comments to.</param>
        /// <param name="content">Content of the comment.</param>
        private static void GenerateSummaryComment(CodeCommentStatementCollection comments, string content)
        {
            comments.Add(new CodeCommentStatement("<summary>", true));

            string nextComment;
            int newlineIndex = content.IndexOf(Environment.NewLine);
            int offset = 0;
            while (newlineIndex != -1)
            {
                nextComment = content.Substring(offset, newlineIndex - offset).Trim();
                comments.Add(new CodeCommentStatement(nextComment, true));
                offset = newlineIndex + Environment.NewLine.Length;
                newlineIndex = content.IndexOf(Environment.NewLine, offset);
            }
            nextComment = content.Substring(offset).Trim();
            comments.Add(new CodeCommentStatement(nextComment, true));

            comments.Add(new CodeCommentStatement("</summary>", true));
        }
        /// <summary>
        /// Takes a multi-line comment defined in a resource file and correctly formats it as a doc comment
        /// for use in code-dom.
        /// </summary>
        /// <param name="resourceComment">The comment to format as a doc comment. This cannot be null.</param>
        /// <param name="isCSharp">Whether or not the doc comment is for C#.</param>
        /// <returns>A collection of comment statements that matches the input resource</returns>
        internal static CodeCommentStatementCollection GetDocComments(string resourceComment, bool isCSharp)
        {
            if (resourceComment == null)
            {
                throw new ArgumentNullException("resourceComment");
            }

            CodeCommentStatementCollection commentCollection = new CodeCommentStatementCollection();
            foreach (string comment in resourceComment.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
            {
                // VB needs to have a prefixing space before each comment, to ensure the ''' XML comments are properly marked
                // Otherwise a comment that starts with a single quote will be broken (build warnings).
                commentCollection.Add(new CodeCommentStatement((isCSharp ? comment : ' ' + comment), true));
            }
            return commentCollection;
        }
 internal static void AddWarningComment(CodeCommentStatementCollection comments, string text) {
     comments.Add(new CodeCommentStatement(Res.GetString(Res.CodegenWarningDetails, text)));
 }
 /// <summary>
 /// Creates a collection of Xml comments surrounded by start end end tags for the named section
 /// </summary>
 /// <param name="section">Section such as "Summary"</param>
 /// <param name="body">The body of the comment</param>
 /// <returns>A collection of Xml comments that can be added to some member.</returns>
 public static CodeCommentStatementCollection GenerateXmlComments(string section, string body)
 {
     CodeCommentStatementCollection result = new CodeCommentStatementCollection();
     result.Add(new CodeCommentStatement(@"<" + section + ">", true));
     result.Add(new CodeCommentStatement(body, true));
     result.Add(new CodeCommentStatement(@"</" + section + ">", true));
     return result;
 }
		private CodeCommentStatementCollection GetSummaryStatements()
		{
			CodeCommentStatementCollection sum = new CodeCommentStatementCollection();
			sum.Add(new CodeCommentStatement("<summary>", true));
			sum.Add(new CodeCommentStatement("", true));
			sum.Add(new CodeCommentStatement("</summary>", true));
			return sum;

		}
		public void Add_Null () {
			CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
			coll.Add ((CodeCommentStatement) null);
		}
Beispiel #20
0
 public void ToCodeDom(CodeCommentStatementCollection comments)
 {
     // comments
     foreach(XmlElement el in this.doc.Root.ChildNodes)
     {
         StringWriter sw = new StringWriter();
         XmlTextWriter w = new XmlTextWriter(sw);
         w.Formatting=Formatting.Indented;
         el.WriteTo(w);
         w.Flush();
         foreach(String s in sw.ToString().Split('\r'))
         {
             if (s.Length<=1)
                 continue;
             if (s[0]=='\n')
                 comments.Add(new CodeCommentStatement(
                     s.Substring(1,s.Length-1),true)
                     );
             else
                 comments.Add(new CodeCommentStatement(
                     s,true)
                     );
         }
     }
 }
		public void AddRange_Self ()
		{
			CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
			coll.Add (new CodeCommentStatement ());
			Assert.AreEqual (1, coll.Count, "#1");
			coll.AddRange (coll);
			Assert.AreEqual (2, coll.Count, "#2");
		}
 /// <summary>
 /// Ensures that the specified custom comment header has been generated in the comments.
 /// </summary>
 /// <param name="comments">The collection of comments being built</param>
 /// <param name="customCommentHeader">The custom comment header to ensure has been emitted</param>
 /// <param name="emittedErrorCommentHeader">The boolean to track whether or not the custom comment header has been emitted</param>
 private static void GenerateCustomAttributesErrorCommentHeader(CodeCommentStatementCollection comments, string customCommentHeader, ref bool emittedErrorCommentHeader)
 {
     if (!emittedErrorCommentHeader)
     {
         // Emit the friendly header text only once
         comments.Add(new CodeCommentStatement(customCommentHeader));
         comments.Add(new CodeCommentStatement(string.Empty /* blank comment */));
         emittedErrorCommentHeader = true;
     }
 }
		public void Constructor2 ()
		{
			CodeCommentStatement ccs1 = new CodeCommentStatement ();
			CodeCommentStatement ccs2 = new CodeCommentStatement ();

			CodeCommentStatementCollection c = new CodeCommentStatementCollection ();
			c.Add (ccs1);
			c.Add (ccs2);

			CodeCommentStatementCollection coll = new CodeCommentStatementCollection (c);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
		}
 /// <summary>
 /// Generate comments indicating attribute propagation failure.
 /// </summary>
 /// <param name="proxyGenerator">The context for generating code.  It cannot be <c>null</c>.</param>
 /// <param name="attributeDeclaration">The attribute declaration to generate as a comment.</param>
 /// <returns>A collection of comments.</returns>
 private static CodeCommentStatementCollection ConstructCodeAttributeFailureComments(CodeDomClientCodeGenerator proxyGenerator, AttributeDeclaration attributeDeclaration)
 {
     // We are generating failure comments in the following example form:
     //
     //    // Unable to generate the following attribute(s) due to the following error(s):
     //    // - The attribute 'System.ComponentModel.DataAnnotations.CustomValidationAttribute' references type 'TestDomainServices.ServerOnlyValidator'.  This is not accessible in the client project.
     //    // [CustomValidationAttribute(typeof(TestDomainServices.ServerOnlyValidator), "IsObjectValid")]
     //    //
     CodeCommentStatementCollection comments = new CodeCommentStatementCollection();
     foreach (string error in attributeDeclaration.Errors)
     {
         comments.Add(new CodeCommentStatement(string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Attribute_FailedToGenerate_ErrorTemplate, error)));
     }
     comments.Add(new CodeCommentStatement(GenerateCodeAttribute(proxyGenerator, attributeDeclaration)));
     comments.Add(new CodeCommentStatement(string.Empty /* blank comment */));
     return comments;
 }
Beispiel #25
0
        /// <summary>
        /// Emit documentation comments for a method parameter
        /// </summary>
        /// <param name="parameter">the parameter being commented</param>
        /// <param name="comment">the comment text</param>
        /// <param name="commentCollection">the comment collection of the CodeDom object to be commented</param>
        public static void EmitParamComments(CodeParameterDeclarationExpression parameter, string comment,
            CodeCommentStatementCollection commentCollection)
        {
            Debug.Assert(parameter != null, "parameter parameter is null");
            Debug.Assert(comment != null, "comment parameter is null");

            string paramComment = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                "<param name=\"{0}\">{1}</param>", parameter.Name, comment);
            commentCollection.Add(new CodeCommentStatement(paramComment, true));
        }
        /// <summary>
        /// Generate comments indicating attribute propagation failure.
        /// </summary>
        /// <param name="errorMessage">The error message to generate an attribute failure comment for.</param>
        /// <returns>A collection of comments.</returns>
        private static CodeCommentStatementCollection ConstructCodeAttributeFailureComments(string errorMessage)
        {
            // We are generating failure comments in the following example form:
            //
            //    // Unable to generate the following attribute(s) due to the following error(s):
            //    // - The attribute 'MyApplication.MyCustomAttribute' threw an exception from the 'ThrowingProperty' property.
            //    //
            CodeCommentStatementCollection comments = new CodeCommentStatementCollection();

            comments.Add(new CodeCommentStatement(string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Attribute_FailedToGenerate_ErrorTemplate, errorMessage)));
            comments.Add(new CodeCommentStatement(string.Empty /* blank comment */));
            return comments;
        }
Beispiel #27
0
        private static void AddSummary(CodeCommentStatementCollection comments, string summary)
        {
            if (String.IsNullOrEmpty(summary))
                return;

            comments.Add(new CodeCommentStatement("<summary>", true));
            comments.Add(new CodeCommentStatement(Util.XmlEncode(summary), true));
            comments.Add(new CodeCommentStatement("</summary>", true));
        }
 internal static void AddWarningComment(CodeCommentStatementCollection comments, string text)
 {
     comments.Add(new CodeCommentStatement(Res.GetString("XmlCodegenWarningDetails", new object[] { text }), false));
 }
        private CodeCommentStatementCollection GetSummaryComment(params string[] comments)
        {
            CodeCommentStatementCollection collection = new CodeCommentStatementCollection();
            if (comments != null && comments.Length > 0)
            {
                for (int i = 0; i < comments.Length; i++)
                    if (!String.IsNullOrEmpty(comments[i]))
                        collection.Add(new CodeCommentStatement(comments[i], true));
            }

            if (collection.Count == 0)
                return collection;

            collection.Insert(0, new CodeCommentStatement("<summary>", true));
            collection.Add(new CodeCommentStatement("</summary>", true));
            return collection;
        }
Beispiel #30
0
		private CodeCommentStatementCollection AddFileBanner(string sInFile, string sOutFile)
		{
			CodeCommentStatementCollection coll = new CodeCommentStatementCollection();

			coll.Add(new CodeCommentStatement("--------------------------------------------------------------------------------------------"));
			coll.Add(new CodeCommentStatement(string.Format(
				"Copyright (c) {0}, SIL International. All rights reserved.", DateTime.Now.Year)));
			coll.Add(new CodeCommentStatement(""));
			coll.Add(new CodeCommentStatement("File: " + Path.GetFileName(sOutFile)));
			coll.Add(new CodeCommentStatement("Responsibility: Generated by IDLImporter"));
			coll.Add(new CodeCommentStatement("Last reviewed: "));
			coll.Add(new CodeCommentStatement(""));
			coll.Add(new CodeCommentStatement("<remarks>"));
			coll.Add(new CodeCommentStatement("Generated by IDLImporter from file " + Path.GetFileName(sInFile)));
			coll.Add(new CodeCommentStatement(""));
			coll.Add(new CodeCommentStatement("You should use these interfaces when you access the COM objects defined in the mentioned"));
			coll.Add(new CodeCommentStatement("IDL/IDH file."));
			coll.Add(new CodeCommentStatement("</remarks>"));
			coll.Add(new CodeCommentStatement("--------------------------------------------------------------------------------------------"));
			return coll;
		}