Repository navigation
Expand file tree
/
Copy pathdocumentation.cs
More file actions
145 lines (123 loc) · 4.02 KB
/
Copy pathdocumentation.cs
File metadata and controls
145 lines (123 loc) · 4.02 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
/// <summary>
/// GOOD: Class documented correctly
/// </summary>
public class Class1
{
protected class Exception1 : ArgumentException
{
}
protected class Exception2 : ArgumentException
{
}
/// <summary>
/// GOOD: This public method is documented correctly
/// <summary>
/// <param name="p1">First parameter</param>
/// <param name="p2">Second parameter</param>
/// <returns>Only via exception</returns>
/// <exception cref= "Exception1" >Exception 1</exception>
/// <exception cref='System.ArgumentException'>Exception 2</exception>
public virtual int method1(int p1, int p2)
{
throw new Exception1();
throw new Exception2();
}
/// BAD: This XML comment is missing several tags
/// <param name="p3">BAD: This parameter does not exist</param>
/// <exception cref="Exception1">BAD: This should say Exception2</exception>
public int method2(int p1, int p2) // $ Alert[cs/xmldoc/missing-exception] Alert[cs/xmldoc/missing-parameter] Alert[cs/xmldoc/missing-return] Alert[cs/xmldoc/missing-summary] Alert[cs/xmldoc/unknown-parameter]
{
return p1 > 0 ? throw new Exception2() : p2;
}
// BAD: Missing documentation comment
public int method3() // $ Alert[cs/xmldoc/missing-xmldoc]
{
return 0;
}
// GOOD: This internal comment does not need documentation
internal int method4()
{
return 0;
}
// BAD: Public class is not documented
public class Class2 // $ Alert[cs/xmldoc/missing-xmldoc]
{
}
// GOOD: Private class does not need documentation
class Class3
{
}
// GOOD: Constructor is private
private Class1(string s)
{
}
/// <summary>
/// GOOD: Constructor is correctly documented
/// </summary>
/// <param name='p'>The parameter</param>
public Class1(int p)
{
}
// BAD: Constructor is public and not documented
public Class1(int a, int b) // $ Alert[cs/xmldoc/missing-xmldoc]
{
}
/// <summary>
/// BAD: Missing a typeparam
/// BAD: Contains an extra typeparam
/// </summary>
/// <typeparam name="X">The type</typeparam>
class Class4<T> { } // $ Alert[cs/xmldoc/missing-type-parameter] Alert[cs/xmldoc/unknown-type-parameter]
/// <summary>
/// GOOD: Type params are correctly labeled
/// </summary>
/// <typeparam name="T1">First type</typeparam>
/// <typeparam name="T2">Second type</typeparam>
class Class5<T1, T2> { }
/// <summary>
/// BAD: Missing a typeparam on a method
/// BAD: Contains an extra typeparam
/// </summary>
/// <typeparam name="T0">BAD typeparam</typeparam>
/// <typeparam name='T2'>GOOD typeparam</typeparam>
void method5<T1, T2>() { } // $ Alert[cs/xmldoc/missing-type-parameter] Alert[cs/xmldoc/unknown-type-parameter]
// BAD: These fields are empty
/// <summary></summary>
/// <param name="p1"/>
/// <param name="p2"> </param>
/// <returns></returns>
/// <typeparam name="T"></typeparam>
public virtual int method4<T>(int p1, int p2) { return p1; } // $ Alert[cs/xmldoc/missing-parameter] Alert[cs/xmldoc/missing-return] Alert[cs/xmldoc/missing-summary] Alert[cs/xmldoc/missing-type-parameter]
}
class Class2 : Class1
{
// GOOD
/// <inheritdoc/>
public Class2(int i) : base(i) { }
// GOOD
/// <inheritdoc/>
public override int method1(int p1, int p2)
{
throw new Exception1();
throw new Exception2();
}
// GOOD: Even if the overridden method is bad.
/// <inheritdoc/>
public override int method4<T>(int p1, int p2) { return p1; }
// GOOD: Has an attribute
[My1]
public void method5()
{
}
// BAD: Has only System.Runtime.CompilerServices attribute
[System.Runtime.CompilerServices.My2]
public void method6() // $ Alert[cs/xmldoc/missing-xmldoc]
{
}
}
internal class My1Attribute : Attribute { }
namespace System.Runtime.CompilerServices
{
internal class My2Attribute : Attribute { }
}