-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocToken.cs
106 lines (75 loc) · 3.52 KB
/
DocToken.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
98
99
100
101
102
103
104
105
106
using System;
using System.Reflection;
using System.Text;
namespace CSToMD {
internal abstract class DocToken {
protected DocToken(MemberInfo mi, Type o) {
token_type = mi.MemberType;
owner = o;
}
public static DocToken from(MemberInfo mi, Type o) {
if ( mi.GetType().IsSubclassOf(typeof(FieldInfo)) ) return new DocFieldToken((FieldInfo)mi, o);
if ( mi.GetType().IsSubclassOf(typeof(PropertyInfo)) ) return new DocPropertyToken((PropertyInfo)mi, o);
if ( mi.GetType().IsSubclassOf(typeof(MethodBase)) ) return new DocMethodToken((MethodBase)mi, o);
if ( mi.GetType().IsSubclassOf(typeof(EventInfo)) ) return new DocEventToken((EventInfo)mi, o);
// Hopefully will never encounter this
System.Console.WriteLine(mi.GetType().FullName);
throw new NotImplementedException("There's another info type??");
}
public virtual string returns() => "N/A";
public virtual string name() => "N/A";
public virtual string description() => "N/A";
public virtual string pseudocode() => "N/A";
private Type owner;
public MemberTypes token_type { get; private set; }
public override string ToString() {
StringBuilder sb = new StringBuilder("| ");
sb.Append(SignatureExtensions.TypeName(owner));
sb.Append(" | ");
sb.Append(name());
sb.Append(" | ");
sb.Append(returns());
sb.Append(" | ");
sb.Append(token_type.ToString());
sb.Append(" | ");
sb.Append(description());
sb.Append(" | ");
sb.Append(pseudocode());
sb.Append(" |");
return sb.ToString();
}
}
internal class DocFieldToken : DocToken {
public DocFieldToken(FieldInfo _fi, Type o) : base(_fi, o) { fi = _fi; }
private FieldInfo fi;
public override string name() => fi.GetSignature(false);
public override string returns() => SignatureExtensions.TypeName(fi.FieldType);
}
internal class DocPropertyToken : DocToken {
public DocPropertyToken(PropertyInfo _pi, Type o) : base(_pi, o) { pi = _pi; }
private PropertyInfo pi;
public override string name() => pi.GetSignature(false);
public override string returns() => SignatureExtensions.TypeName(pi.PropertyType);
}
internal class DocMethodToken : DocToken {
public DocMethodToken(MethodBase _mi, Type o) : base(_mi, o) { mi = _mi; }
private MethodBase mi;
public override string name() {
try {
return ((MethodInfo)mi).GetSignature(false);
} catch {
return ((ConstructorInfo)mi).GetSignature();
}
}
public override string pseudocode() => "[ INSERT PSEUDOCODE HERE ]";
public override string returns() => SignatureExtensions.TypeName(mi.GetReturnType());
public override string description() => "[ INSERT DESCRIPTION HERE ]";
}
internal class DocEventToken : DocToken {
public DocEventToken(EventInfo _ei, Type o) : base(_ei, o) { ei = _ei; }
private EventInfo ei;
public override string name() => ei.GetSignature(false);
public override string returns() { try { return SignatureExtensions.TypeName(ei.EventHandlerType); } catch { return "[ INSERT EVENT DELEGATE TYPE HERE ]"; } }
public override string description() => "[ INSERT DESCRIPTION HERE ]";
}
}