C#如何抽取cs文件中各个函数的摘要信息和“#region '功能简短说明'”行。
解决方案 »
- 递归 查询重复数 的问题
- 用Profile做购物车,已经登录的用户,怎么获得ID
- WebForm、WPF、WinForm,三者如何能共享變量?
- XML数据导入SQL的问题
- 急求:如何读取以string类型发送过来的XML中的信息
- 用对称加密法,如何让加密后的数据只含有数字和字母,而不带其他的符号(比如=,;等)
- 也就是怎样通过 pictureBox.Image 对象的图像信息部分数据读取到一个MemoryStream对象中???
- C# 在后台怎么返回一个JSON对象?
- 如何实现监视文件被复制功能?
- 怎样使主窗体的工具栏按钮(ToolBar上的Button)控制子窗体的开关,以及其他一些操作(比如说:查找,保存等)
- c#中,listBox.Text相关问题。
- 我想做一个串口接收GPS的的小程序,但是要如何完整接收GPS发过来的数据呢?
这个没法实现吧,因为#region事实上也就是一些注释性的东西C#如何抽取cs文件中各个函数的摘要信息
这个可以实现:
1、到http://www.codeplex.com/csparser下载一个release,在你的项目上引用其中的CSParser.dll文件
2、在你的项目中,添加一个cs文件,写入下面的代码: using Mono.CSharp; public sealed class CSharpCodeVisualizer
{
private CodeCompileUnit codeCompileUnit__; /// <summary>
/// Parses the code and generate the compiled units.
/// </summary>
/// <param name="_code">The source code that is being parsed.</param>
/// <returns>Zero if success, otherwise a non-zero value would return.</returns>
/// <res>
/// For more information about compiled units, please refer to <see cref="System.CodeDom.CodeCompileUnit"/>.
/// </res>
/// <seealso cref="System.CodeDom.CodeCompileUnit"/>
public int Parse(string _code)
{
MemoryStream memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_code));
CSharpParser parser = new CSharpParser(null, memoryStream, null);
int ret = parser.parse();
codeCompileUnit__ = parser.Builder.CurrCompileUnit;
return ret;
} /// <summary>
/// Gets the compiled unit information after the calling of <see cref="Parse"/> method.
/// </summary>
public CodeCompileUnit CodeCompileUnit
{
get { return codeCompileUnit__; }
}
}3、调用上面的方法:TextReader reader = new TextReader("c:\\abc.cs");
string code = reader.ReadToEnd();
CSharpCodeVisualizer visualizer = new CSharpCodeVisualizer();
visualizer.Parse(code);
foreach (CodeNamespace ns in visualizer.CodeCompileUnit.Namespaces)
{
// ns就是你代码中的namespaces
foreach (CodeTypeDeclaration typeDeclaration in ns.Types)
{
// typeDeclaration就是你代码中的所有类型(包括class、interface、enum等)
foreach (CodeTypeMember member in typeDeclaration.Members)
{
// member就是每个类型中的成员,有property、method等,你自己可以通过member中的属性进行判断
}
}
}
希望这些对你有帮助!
先生,C#或net开发环境自身没有这个功能吗
晕死,我自己需求还没搞清楚。哈哈。VS不是有个Class Explorer么?里面不是什么都有了?
你指的是什么?
是
/// <summary>
/// Gets the compiled unit information after the calling of <see cref="Parse"/> method.
/// </summary>来对一个方法进行说明的文字吗
2.#region 说明性文字
这里可以是任何东西,方法,属性.....
#endregion