private static void InitXsdDataContractExporter(WsdlExporter exporter, XmlCommentFormat format) { object dataContractExporter; XsdDataContractExporter xsdExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); exporter.State.Add(typeof(XsdDataContractExporter), xsdExporter); } else { xsdExporter = (XsdDataContractExporter)dataContractExporter; } if (xsdExporter.Options == null) { xsdExporter.Options = new ExportOptions(); } if (!(xsdExporter.Options.DataContractSurrogate is XmlCommentsDataSurrogate)) { xsdExporter.Options.DataContractSurrogate = new XmlCommentsDataSurrogate(xsdExporter.Options.DataContractSurrogate, format); } }
internal static void ExportEndpoint(WsdlExporter exporter, XmlCommentFormat format) { foreach (XmlSchema schema in exporter.GeneratedXmlSchemas.Schemas()) { foreach (XmlSchemaObject schemaObj in schema.Items) { ConvertObjectAnnotation(schemaObj); } } XmlCommentsUtils.ClearCache(); }
public static string GetFormattedComment(XmlDocument commentsDoc, MemberInfo member, XmlCommentFormat format) { string result; if (memberCommentCache.TryGetValue(member, out result)) return result; XmlNode commentNode = GetCommentNodeForMember(commentsDoc, member); if (commentNode != null) result = GetFormattedComment(member, commentNode, format); else result = null; memberCommentCache[member] = result; return result; }
internal static void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context, XmlCommentFormat format, string implementationClass) { InitXsdDataContractExporter(exporter, format); XmlDocument commentsDoc = XmlCommentsUtils.LoadXmlComments(context.Contract.ContractType, true); if (commentsDoc == null) { return; } //See if we're being asked to get the comments from a specific implementation class //otherwise we can just use the interface contract itself Type type = context.Contract.ContractType; if (!String.IsNullOrEmpty(implementationClass)) { Assembly assembly = type.Assembly; Type implType = assembly.GetType(implementationClass, false, true); if (implType != null) { type = implType; } } string comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, type, format); if (comment != null) { // Set the doc element; if this isn't done first, there is no XmlElement in the // DocumentElement property. context.WsdlPortType.Documentation = String.Empty; //Now add the XML comments XmlDocument xmlDoc = context.WsdlPortType.DocumentationElement.OwnerDocument; XmlElement xmlDocumentation = xmlDoc.CreateElement("comments"); xmlDocumentation.InnerXml = comment; context.WsdlPortType.DocumentationElement.AppendChild(xmlDocumentation); } foreach (Operation op in context.WsdlPortType.Operations) { OperationDescription opDescription = context.GetOperationDescription(op); MemberInfo mi = opDescription.SyncMethod; if (mi == null) { mi = opDescription.BeginMethod; } //See if we're being asked to get the comments from a specific implementation class //otherwise we can just use the interface contract itself if (!String.IsNullOrEmpty(implementationClass)) { Assembly assembly = type.Assembly; Type implType = assembly.GetType(implementationClass, false, true); if (implType != null) { MethodInfo[] implMethods = implType.GetMethods(); foreach (MethodInfo implMethod in implMethods) { if (implMethod.Name == mi.Name) { mi = implMethod; break; } } } } comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, mi, format); if (comment != null) { // Set the doc element; if this isn't done first, there is no XmlElement in the // DocumentElement property. op.Documentation = String.Empty; //Now add the XML comments XmlDocument xmlDoc = op.DocumentationElement.OwnerDocument; XmlElement xmlDocumentation = xmlDoc.CreateElement("comments"); xmlDocumentation.InnerXml = comment; op.DocumentationElement.AppendChild(xmlDocumentation); } } }
public XmlCommentsAttribute(XmlCommentFormat format) { this.format = format; }
private static string GetFormattedComment(MemberInfo member, XmlNode commentNode, XmlCommentFormat format) { string result; if (format == XmlCommentFormat.Default) { result = commentNode.InnerXml.Trim('\n', '\r', ' '); } else { string summary = GetTextFromNode(commentNode, "summary"); List <string> paramList = GetParams(commentNode); string returnValue = GetTextFromNode(commentNode, "returns");; List <string> comments = new List <string>(); if (!string.IsNullOrEmpty(summary)) { comments.Add(summary); } comments.AddRange(paramList); if (!string.IsNullOrEmpty(returnValue)) { comments.Add("@return " + returnValue); } result = String.Join("\n", comments.ToArray()); } bool handled = false; if (FormatComment != null) { handled = FormatComment(ref result); //Allows custimizing the formatted comment } if (!handled) { result = FixReferences(member, result); } return(result); }
public static IEnumerable <string> ParseAndReformatComment(string documentation, XmlCommentFormat format, bool wrapLongLines) { if (format == XmlCommentFormat.Default || ContainsDotNetXMLCommentTags(documentation)) { return(ExtractLines(documentation, wrapLongLines)); } else { string summary = string.Empty; Match m = Regex.Match(documentation, "^@", RegexOptions.Multiline); if (m.Success) { summary = documentation.Substring(0, m.Index); if (summary.Length > 0) { summary = "<summary>\r\n" + summary + "\r\n</summary>\r\n"; } documentation = documentation.Substring(m.Index); //change "@return {some text}" to "<returns>{some text}</returns>" documentation = Regex.Replace(documentation, "^@return\\s+(?<text>.*)$", "<returns>${text}</returns>", RegexOptions.Multiline); //change "@param paramname {some text}" to "<param name="paramname">{some text}</param>" documentation = Regex.Replace(documentation, "^@param\\s+(?<name>\\S+)\\s+(?<text>.*)$", "<param name=\"${name}\">${text}</param>", RegexOptions.Multiline); } else { documentation = "<summary>\r\n" + documentation + "\r\n</summary>\r\n"; }; return(ExtractLines(summary + documentation, true)); } }
internal static void ExportEndpoint(WsdlExporter exporter, XmlCommentFormat format) { foreach (XmlSchema schema in exporter.GeneratedXmlSchemas.Schemas()) { foreach (XmlSchemaObject schemaObj in schema.Items) { ConvertObjectAnnotation(schemaObj); } } XmlCommentsUtils.ClearCache(); }
public XmlCommentsAttribute(XmlCommentFormat format) { this.format = format; }
public static IEnumerable<string> ParseAndReformatComment(string documentation, XmlCommentFormat format, bool wrapLongLines) { if (format == XmlCommentFormat.Default || ContainsDotNetXMLCommentTags(documentation)) return ExtractLines(documentation, wrapLongLines); else { string summary = string.Empty; Match m = Regex.Match(documentation, "^@", RegexOptions.Multiline); if (m.Success) { summary = documentation.Substring(0, m.Index); if (summary.Length > 0) summary = "<summary>\r\n" + summary + "\r\n</summary>\r\n"; documentation = documentation.Substring(m.Index); //change "@return {some text}" to "<returns>{some text}</returns>" documentation = Regex.Replace(documentation, "^@return\\s+(?<text>.*)$", "<returns>${text}</returns>", RegexOptions.Multiline); //change "@param paramname {some text}" to "<param name="paramname">{some text}</param>" documentation = Regex.Replace(documentation, "^@param\\s+(?<name>\\S+)\\s+(?<text>.*)$", "<param name=\"${name}\">${text}</param>", RegexOptions.Multiline); } else documentation = "<summary>\r\n" + documentation + "\r\n</summary>\r\n"; ; return ExtractLines(summary + documentation, true); } }
private static string GetFormattedComment(MemberInfo member, XmlNode commentNode, XmlCommentFormat format) { string result; if (format == XmlCommentFormat.Default) { result = commentNode.InnerXml.Trim('\n', '\r', ' '); } else { string summary = GetTextFromNode(commentNode, "summary"); List<string> paramList = GetParams(commentNode); string returnValue = GetTextFromNode(commentNode, "returns"); ; List<string> comments = new List<string>(); if (!string.IsNullOrEmpty(summary)) comments.Add(summary); comments.AddRange(paramList); if (!string.IsNullOrEmpty(returnValue)) comments.Add("@return " + returnValue); result = String.Join("\n", comments.ToArray()); } bool handled = false; if (FormatComment != null) handled = FormatComment(ref result); //Allows custimizing the formatted comment if (!handled) result = FixReferences(member, result); return result; }
/// <summary> /// Adds the normal C# comments to the generated WSDL to make documentation automatic /// </summary> /// <param name="format">The format to use</param> /// <param name="implementationClass"> /// The name of the class implementing the interface whose comments should be used (leave blank to use the interface) /// </param> public XmlCommentsAttribute(XmlCommentFormat format, string implementationClass) { this.format = format; this.implementationClass = implementationClass; }
public XmlCommentsDataSurrogate(IDataContractSurrogate prevSurrogate, XmlCommentFormat format) : this(prevSurrogate) { this.format = format; }
private static void InitXsdDataContractExporter(WsdlExporter exporter, XmlCommentFormat format) { object dataContractExporter; XsdDataContractExporter xsdExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); exporter.State.Add(typeof(XsdDataContractExporter), xsdExporter); } else { xsdExporter = (XsdDataContractExporter)dataContractExporter; } if (xsdExporter.Options == null) xsdExporter.Options = new ExportOptions(); if (!(xsdExporter.Options.DataContractSurrogate is XmlCommentsDataSurrogate)) xsdExporter.Options.DataContractSurrogate = new XmlCommentsDataSurrogate(xsdExporter.Options.DataContractSurrogate, format); }
internal static void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context, XmlCommentFormat format) { InitXsdDataContractExporter(exporter, format); XmlDocument commentsDoc = XmlCommentsUtils.LoadXmlComments(context.Contract.ContractType); if (commentsDoc == null) { return; } string comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, context.Contract.ContractType, format); if (comment != null) { context.WsdlPortType.Documentation = comment; } foreach (Operation op in context.WsdlPortType.Operations) { OperationDescription opDescription = context.GetOperationDescription(op); MemberInfo mi = opDescription.SyncMethod; if (mi == null) { mi = opDescription.BeginMethod; } #if NET45 if (mi == null) { mi = opDescription.TaskMethod; } #endif comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, mi, format); if (comment != null) { op.Documentation = comment; } } }
public static string GetFormattedComment(XmlDocument commentsDoc, MemberInfo member, XmlCommentFormat format) { string result; if (memberCommentCache.TryGetValue(member, out result)) { return(result); } XmlNode commentNode = GetCommentNodeForMember(commentsDoc, member); if (commentNode != null) { result = GetFormattedComment(member, commentNode, format); } else { result = null; } memberCommentCache[member] = result; return(result); }
public XmlCommentsDataSurrogate(IDataContractSurrogate prevSurrogate, XmlCommentFormat format) : this(prevSurrogate) { this.format = format; }
internal static void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context, XmlCommentFormat format) { InitXsdDataContractExporter(exporter, format); XmlDocument commentsDoc = XmlCommentsUtils.LoadXmlComments(context.Contract.ContractType, true); if (commentsDoc == null) return; string comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, context.Contract.ContractType, format); if (comment != null) { context.WsdlPortType.Documentation = comment; } foreach (Operation op in context.WsdlPortType.Operations) { OperationDescription opDescription = context.GetOperationDescription(op); MemberInfo mi = opDescription.SyncMethod; if (mi == null) mi = opDescription.BeginMethod; comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, mi, format); if (comment != null) { op.Documentation = comment; } } }