forked from simpleway2016/JMS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MethodDocument.cs
69 lines (60 loc) · 1.97 KB
/
MethodDocument.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace JMS.AssemblyDocumentReader
{
public class MethodDocument
{
public MethodInfo MethodInfo { get;}
public string Name { get; set; }
public string Comment { get; set; }
public List<ItemDocument> Parameters { get; }
/// <summary>
/// 泛型方法里,泛型的注释
/// </summary>
public List<ItemDocument> TypeParameters { get; }
public string ReturnComment { get; set; }
public MethodDocument(MethodInfo method)
{
this.MethodInfo = method;
this.Name = method.Name;
this.Parameters = new List<ItemDocument>();
this.TypeParameters = new List<ItemDocument>();
}
/// <summary>
/// 返回xml格式的注释
/// </summary>
/// <returns></returns>
public string GetXmlComment()
{
XmlDocument xmldoc = new XmlDocument();
var root = xmldoc.CreateElement("root");
var summaryEle = xmldoc.CreateElement("summary");
summaryEle.InnerText = this.Comment;
root.AppendChild(summaryEle);
foreach( var p in Parameters)
{
var paramEle = xmldoc.CreateElement("param");
paramEle.InnerText = p.Comment;
paramEle.SetAttribute("name", p.Name);
root.AppendChild(paramEle);
}
if (!string.IsNullOrEmpty(ReturnComment))
{
var returnsEle = xmldoc.CreateElement("returns");
returnsEle.InnerText = this.ReturnComment;
root.AppendChild(returnsEle);
}
return root.ToXmlString();
}
public override string ToString()
{
return Name;
}
}
}