You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-69Lines changed: 9 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,15 @@
5
5
A Visual Studio extension that lets you generate common methods in C# - parameterless constructors, `GetHashCode`, `Equals`, and equality operators - with XML documentation automatically inserted for you.
6
6
7
7
# ❓ How does it work?
8
-
When you install the extension, you get four new code actions for classes and structs!
8
+
When you install the extension, you get 7 new code actions for classes and structs!
9
9
10
10
-`XML: Add Equality Methods to Fields`: When you click this, it generates `GetHashCode`, `Equals`, `IEquatable`, and equality operators for all fields, + XML documentation.
11
11
-`XML: Add Equality Methods to Properties`: Same as the one above, but for properties.
12
12
-`XML: Add Equality Methods to Members`: Same as the one above, but for both Fields and Properties.
13
13
-`XML: Add Parameterless Constructor`: Adds an empty constructor without any parameters, with XML documentation
14
+
- There's also the three other options: Equality methods, but with `(Use inheritdoc)`. These apply an `<inheritdoc cref="..." />` to methods like GetHashCode, IEquatable.Equals, and object.Equals.
You no longer have to manually write XML documentation for methods like `GetHashCode` or `Equals` - even an `<inheritdoc ... />` can take some time to write! AddWithXmlDoc does that for you.
18
19
@@ -31,73 +32,7 @@ public class Class1
31
32
}
32
33
```
33
34
34
-
Right click on `Class1`. Click `XML: Add Equality Methods to Members`.
35
-
Our class now looks like this. With just one click.
36
-
37
-
```cs
38
-
publicclassClass1 : IEquatable<Class1>
39
-
{
40
-
publicstringGreeting { get; set; }
41
-
="Welcome to AddWithXmlDoc!"
42
-
43
-
/// <summary>
44
-
/// Determines if this instance is equal to the other instance of type <see cref = "Class1"/>.
45
-
/// </summary>
46
-
/// <param name = "other">The other value to compare this instance with.</param>
47
-
/// <returns>A boolean that, if <seelangword="true"/>, indicates that <paramref name = "other"/> is equal to this instance, is of same type as this instance, and is not null.</returns>
48
-
publicoverrideboolEquals(object?other)
49
-
{
50
-
returnotherisClass1value&&Equals(value);
51
-
}
52
-
53
-
/// <summary>
54
-
/// Determines if this instance is equal to the other instance of type <see cref = "Class1"/>.
55
-
/// </summary>
56
-
/// <param name = "other">The other instance to compare this instance with.</param>
57
-
/// <returns>A boolean that, if <seelangword="true"/>, indicates that <paramref name = "other"/> is equal to this instance.</returns>
58
-
publicboolEquals(Class1?other)
59
-
{
60
-
returnthis.Greeting==other?.Greeting;
61
-
}
62
-
63
-
/// <summary>
64
-
/// Computes the hash code for this object.
65
-
/// </summary>
66
-
/// <returns>This object's hash code.</returns>
67
-
publicoverrideintGetHashCode()
68
-
{
69
-
varhashCode=newHashCode();
70
-
hashCode.Add(this.Greeting);
71
-
returnhashCode.ToHashCode();
72
-
}
73
-
74
-
/// <summary>
75
-
/// Determines if <paramref name = "left"/> is equal to <paramref name = "right"/>.
76
-
/// </summary>
77
-
/// <param name = "left">The value to compare from.</param>
78
-
/// <param name = "right">The value to compare with.</param>
79
-
/// <returns><seelangword="true"/> if the left parameter is same as the right parameter, otherwise <seelangword="false"/>.</returns>
/// Determines if <paramref name = "left"/> is not equal to <paramref name = "right"/>.
87
-
/// </summary>
88
-
/// <param name = "left">The value to compare from.</param>
89
-
/// <param name = "right">The value to compare with.</param>
90
-
/// <returns><seelangword="true"/> if the left parameter is different compared to the right parameter, otherwise <seelangword="false"/> if both are same.</returns>
Or, instead, click `XML: Add Parameterless Constructor`. Our class now looks like this.
35
+
Right click on `Class1`. Click `XML: Add Parameterless Constructor`. Our class now looks like this.
101
36
102
37
```cs
103
38
publicclassClass1
@@ -114,6 +49,11 @@ public class Class1
114
49
}
115
50
```
116
51
52
+
It also supports generating `GetHashCode()`, `IEquatable.Equals`, `object.Equals`, `==`, and `!=`. Examples of generated code for such methods are documented in the docs. (See below)
53
+
54
+
# 📄 Docs
55
+
See [docs.md](docs/docs.md)
56
+
117
57
# 🧱 Prerequisites
118
58
AddWithXmlDoc supports all Visual Studio versions starting from Visual Studio 2022. You should have
119
59
Visual Studio versions at least 2022 to use AddWithXmlDoc.
- 1.1. [Via Visual Studio Marketplace](#install-vsm)
4
+
- 1.2. [Via GitHub](#install-gh)
5
+
2.[Usage](#usage)
6
+
- 2.1. [Initial Code](#code-init)
7
+
- 2.2. [Code after clicking to generate equality methods for fields with XML documentation](#code-eq-fields-xml)
8
+
- 2.3. [Code after clicking to generate equality methods for fields with XML documentation, using inheritdoc where possible](#code-eq-fields-xml-inheritdoc)
9
+
10
+
<aname="installation"></a>
11
+
12
+
# 1. Installation
13
+
This clause describes how to install AddWithXmlDoc.
14
+
15
+
<aname="install-vsm"></a>
16
+
17
+
### 1.1. Via Visual Studio Marketplace
18
+
Go to https://marketplace.visualstudio.com/items?itemName=winscripter.ExtVSAddWithXmlDoc. Click the Green download button. Double click the downloaded `.vsix` file and follow the instructions.
19
+
20
+
<aname="install-gh"></a>
21
+
22
+
### 1.2. Via GitHub
23
+
Go to the [Releases Page](https://github.com/winscripter/AddWithXmlDoc/releases). Click on the latest release, click on the `.vsix` file. Double click the downloaded `.vsix` file and follow the instructions.
24
+
25
+
<aname="usage"></a>
26
+
27
+
# 2. Usage
28
+
29
+
<aname="code-init"></a>
30
+
31
+
### 2.1. Initial code
32
+
Right click on the class name, and click `Quick Actions and Refactorings`, with the light bulb to the left of it.
33
+
34
+

35
+
36
+
<aname="code-eq-fields-xml"></a>
37
+
38
+
### 2.2. Code after clicking to generate equality methods for fields with XML documentation
39
+
We had to decrease the scaling so the image isn't too big. As you can see, lots of code was generated. That much time was saved!
40
+
41
+

42
+
43
+
<aname="code-eq-fields-xml-inheritdoc"></a>
44
+
45
+
### 2.3. Code after clicking to generate equality methods for fields with XML documentation, using inheritdoc where possible
46
+
We had to decrease the scaling so the image isn't too big. As you can see, lots of code was generated. That much time was saved!
0 commit comments