有什么方法可以将C#XML注释转换为C#注释? [英] Any way to convert C# XML Comments into C# Comment?

查看:63
本文介绍了有什么方法可以将C#XML注释转换为C#注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:ILSPY,DotPeek和JustDecompile自动支持我正在寻找的内容.

Update: ILSPY, DotPeek and JustDecompile automatically support what I am looking.

我只想将C#XML注释转换为注释.

I just want to convert my C# XML Comments into Comments.

输入

<member name="P:...">
      <summary>.......</summary>
      <returns>
        ......
      </returns>
</member>

输出

/// <summary>
/// ...
/// </summary>
/// <returns>...</returns>

推荐答案

如果您最终尝试摆脱困境,没有更多的上下文,这会将Xml转换为注释.这里没有什么棘手的事情...

Without more context for what your ultimately trying to get out of it, this should convert Xml into comments. Nothing real tricky going on here...

string content =
@"<member name=""P:..."">
  <summary>This is the summary.</summary>
  <returns>This is the return info.</returns>
  </member>";

XDocument doc = XDocument.Parse(content);                        
foreach (var member in doc.Descendants("member"))
{
     StringBuilder sb = new StringBuilder();

     sb.AppendLine("/// <summary>");
     sb.AppendLine("/// " + member.Descendants("summary").Select(e => e.Value).FirstOrDefault());
     sb.AppendLine("/// </summary>");

     sb.AppendLine("/// <returns>");
     sb.AppendLine("/// " + member.Descendants("returns").Select(e => e.Value).FirstOrDefault());
     sb.AppendLine("/// </returns>");

     // sb.ToString() contains the comments for this member
 }

您可能需要做更多的事情才能完全按照您的要求获得它.

You'll probably need to do more to get it exactly how you want.

这篇关于有什么方法可以将C#XML注释转换为C#注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆