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() { 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"); }
static void AddDocComments(List <string> ss, CodeCommentStatementCollection comments) { if (ss != null && ss.Count > 0 && comments != null) { comments.Add(new CodeCommentStatement("<summary>", true)); ss.ForEach(s => comments.Add(new CodeCommentStatement(s, true))); comments.Add(new CodeCommentStatement("</summary>", true)); } }
/// <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); }
public void AddComment(CodeCommentStatementCollection codeCommentStatementCollection, IEnumerable <string> comments) { codeCommentStatementCollection.Add(new CodeCommentStatement("<summary>", true)); foreach (var comment in comments) { codeCommentStatementCollection.Add(new CodeCommentStatement(comment, true)); } codeCommentStatementCollection.Add(new CodeCommentStatement("</summary>", true)); }
/// <summary> /// 添加注释 /// </summary> static void AddDocumentComment(CodeCommentStatementCollection comments, string commentContent) { if (!string.IsNullOrEmpty(commentContent)) { comments.Add(new CodeCommentStatement(new CodeComment("<summary>", true))); comments.Add(new CodeCommentStatement(new CodeComment(commentContent, true))); comments.Add(new CodeCommentStatement(new CodeComment("</summary>", true))); } }
static void AddDocComments(string description, CodeCommentStatementCollection comments) { if (description != null && comments != null) { comments.Add(new CodeCommentStatement("<summary>", true)); comments.Add(new CodeCommentStatement(description, true)); comments.Add(new CodeCommentStatement("</summary>", true)); } }
/// <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)); }
/// <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)); }
/// <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; } }
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)); }
public static void AddSummary(this CodeCommentStatementCollection commentCollection, string comment) { if (string.IsNullOrEmpty(comment)) { return; } commentCollection.Add(new CodeCommentStatement("<summary>", true)); commentCollection.Add(new CodeCommentStatement(comment, true)); commentCollection.Add(new CodeCommentStatement("</summary>", true)); }
public static void AddSummary(this CodeCommentStatementCollection comments, object value) { if (value == null || string.IsNullOrEmpty(value.ToString()) == true) { return; } comments.Add(new CodeCommentStatement("<summary>", true)); comments.Add(new CodeCommentStatement(value.ToString(), true)); comments.Add(new CodeCommentStatement("</summary>", true)); }
private static void GenerateXmlDoc(CodeCommentStatementCollection comments, string summary, params KeyValuePair <string, string>[] parameters) { comments.Add(new CodeCommentStatement("<summary>", true)); comments.Add(new CodeCommentStatement(summary, true)); comments.Add(new CodeCommentStatement("</summary>", true)); foreach (var parameter in parameters) { comments.Add( new CodeCommentStatement( string.Format("<param name=\"{0}\">{1}</param>", parameter.Key, parameter.Value), 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); }
public void Add() { CodeCommentStatement ccs1 = new CodeCommentStatement(); CodeCommentStatement ccs2 = new CodeCommentStatement(); CodeCommentStatementCollection coll = new CodeCommentStatementCollection(); Assert.AreEqual(0, coll.Add(ccs1), "#1"); Assert.AreEqual(1, coll.Count, "#2"); Assert.AreEqual(0, coll.IndexOf(ccs1), "#3"); Assert.AreEqual(1, coll.Add(ccs2), "#4"); Assert.AreEqual(2, coll.Count, "#5"); Assert.AreEqual(1, coll.IndexOf(ccs2), "#6"); }
public static void AddRange(this CodeCommentStatementCollection self, params object[] comments) { foreach (var comment in Sequence.Expand(comments)) { self.Add(new CodeCommentStatement(comment.ToString())); } }
public CodeCommentStatementCollection GenerateCodeDom(ICodeDOMTranslationOptions options) { List <IComment> nonDocCom = new List <IComment>(); List <IDocumentationComment> docCom = new List <IDocumentationComment>(); foreach (IComment ic in this) { if (ic is IDocumentationComment) { docCom.Add((IDocumentationComment)ic); } else { nonDocCom.Add(ic); } } CodeCommentStatementCollection ccsc = new CodeCommentStatementCollection(); nonDocCom.AddRange(docCom.ToArray()); docCom.Clear(); docCom = null; foreach (IComment ic in nonDocCom) { ccsc.Add(new CodeCommentStatement(ic.GenerateCodeDom(options))); } return(ccsc); }
public CodeCommentStatementCollection GenerateCommentCodeDom(ICodeDOMTranslationOptions options) { CodeCommentStatementCollection ccsc = new CodeCommentStatementCollection(); if (this.Count == 0) { return(ccsc); } CodeCommentStatement[] typeParamComments = new CodeCommentStatement[this.Count]; for (int i = 0; i < this.Count; i++) { IDelegateTypeParameterMember param = this[i]; if (param.DocumentationComment != null && param.DocumentationComment != string.Empty) { string paramName = ""; if (options.NameHandler.HandlesName(param)) { paramName = options.NameHandler.HandleName(param); } else { paramName = param.Name; } ccsc.Add(new CodeCommentStatement(new CodeComment(string.Format("<param name=\"{0}\">{1}</param>", paramName, param.DocumentationComment), true))); } } return(ccsc); }
public CodeCommentStatementCollection GenerateCommentCodeDom(ICodeDOMTranslationOptions options) { CodeCommentStatementCollection ccsc = new CodeCommentStatementCollection(); if (this.Count == 0) { return(ccsc); } CodeCommentStatement[] typeParamComments = new CodeCommentStatement[this.Count]; for (int i = 0; i < this.Count; i++) { TItem itpm = this[i]; if (itpm.DocumentationComment != null && itpm.DocumentationComment != string.Empty) { string itpmName = ""; if (options.NameHandler.HandlesName(itpm)) { itpmName = options.NameHandler.HandleName(itpm); } else { itpmName = itpm.Name; } ccsc.Add(new CodeCommentStatement(new CodeComment(string.Format("<typeparam name=\"{0}\">{1}</typeparam>", itpmName, itpm.DocumentationComment), true))); } } return(ccsc); }
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"); }
public static void AddRange(this CodeCommentStatementCollection self, IEnumerable <CodeCommentStatement> comments) { foreach (var c in comments) { self.Add(c); } }
/// <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 'ServerOnlyValidator'. This is not accessible in the client project. // // [CustomValidationAttribute(typeof(ServerOnlyValidator), "IsObjectValid")] var 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); }
private CodeCommentStatementCollection BuildDocComments(params string[] comment) { CodeCommentStatementCollection comments = new CodeCommentStatementCollection(); if (!IsNullOrEmpty(comment)) { comments.Add(new CodeCommentStatement("<summary>", true)); for (int i = 0; i < comment.Length; i++) { comments.Add(new CodeCommentStatement(comment[i], true)); } comments.Add(new CodeCommentStatement("<summary>", true)); } return(comments); }
public void ToCodeDom(CodeCommentStatementCollection comments) { // comments foreach (XmlElement el in this.doc.Root.ChildNodes) { comments.Add(new CodeCommentStatement(el.OuterXml, true)); } }
static void AddDocComments(docMember dm, CodeCommentStatementCollection comments, string[] extra = null) { if (dm != null && dm.summary != null) { comments.Add(new CodeCommentStatement("<summary>", true)); var noIndent = StringFunctions.TrimTrimIndentsOfArray(dm.summary.Text); if (noIndent != null) { foreach (var item in noIndent) { comments.Add(new CodeCommentStatement(item, true)); } } if (extra != null && extra.Length > 0) { foreach (var c in extra) { comments.Add(new CodeCommentStatement(c, true)); } } comments.Add(new CodeCommentStatement("</summary>", true)); } else if (extra != null && extra.Length > 0) { comments.Add(new CodeCommentStatement("<summary>", true)); foreach (var c in extra) { comments.Add(new CodeCommentStatement(c, true)); } comments.Add(new CodeCommentStatement("</summary>", true)); } }
public static void Add(this CodeCommentStatementCollection comments, string name, object value) { if (value == null || string.IsNullOrEmpty(value.ToString()) == true) { return; } comments.Add(new CodeCommentStatement(string.Format("{0}: {1}", name, value))); }
public static void Add(this CodeCommentStatementCollection comments, string name, DateTime value) { if (value == DateTime.MinValue) { return; } comments.Add(new CodeCommentStatement(string.Format("{0}: {1}", name, value))); }
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"); }
static void AddDocComments(docMember dm, CodeCommentStatementCollection comments, string[] extra = null) { if (dm != null && dm.summary != null) { if (extra != null && extra.Length > 0) { comments.Add(new CodeCommentStatement(StringFunctions.IndentedArrayToString(dm.summary.Text.Union(extra)), true)); } else { comments.Add(new CodeCommentStatement(StringFunctions.IndentedArrayToString(dm.summary.Text), true)); } } else if (extra != null && extra.Length > 0) { comments.Add(new CodeCommentStatement(StringFunctions.IndentedArrayToString(extra), true)); } }