-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMethod.cs
97 lines (81 loc) · 2.71 KB
/
Method.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
// Xml Documentation Generator (XDG)
// Copyright (C) 2012, Ilmar Kruis
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one
// at http://mozilla.org/MPL/2.0/.
//
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Mono.Cecil;
namespace XDG
{
class Method
{
public class Parameter
{
public string Name;
public string Type;
public string Doc;
}
public string Name { get; set; }
public string NameWithTypes { get; set; }
public string Summary { get; set; }
public string Remarks { get; set; }
public string Access { get; set; }
public string ReturnType { get; set; }
public string ReturnDocs { get; set; }
public List<Parameter> Parameters { get; set; }
public Method(MethodDefinition method)
{
Name = method.Name;
NameWithTypes = BuildNameWithTypes(method);
if (method.IsPublic)
Access = "public";
else if (method.IsFamily)
Access = "protected";
if(method.ReturnType.FullName != "System.Void")
ReturnType = method.ReturnType.ToXdgUrl();
XmlNode doc = Xdg.FindXmlDoc(method);
if (doc != null)
{
Summary = doc.GetElementContent("summary");
Remarks = doc.GetElementContent("remarks");
ReturnDocs = doc.GetElementContent("returns");
}
Parameters = new List<Parameter>();
foreach (ParameterDefinition p in method.Parameters)
{
Parameter param = new Parameter();
param.Name = p.Name;
param.Type = p.ParameterType.ToXdgUrl();
if(doc != null)
param.Doc = doc.GetElementContent("param[@name=\""+p.Name+"\"]");
Parameters.Add(param);
}
}
string BuildNameWithTypes(MethodDefinition method)
{
StringBuilder sb = new StringBuilder();
sb.Append("<strong>");
sb.Append(Name);
sb.Append("</strong>(");
string comma = "";
foreach (ParameterDefinition p in method.Parameters)
{
sb.Append(comma);
sb.Append(Type.GetName(p.ParameterType));
sb.Append(" ");
sb.Append(p.Name);
comma = ", ";
}
sb.Append(")");
return sb.ToString();
}
}
}