Skip to content

Commit de26288

Browse files
committed
Inheritdoc support
1 parent 7e6c503 commit de26288

21 files changed

+471
-158
lines changed

README.md

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
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.
66

77
# ❓ 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!
99

1010
- `XML: Add Equality Methods to Fields`: When you click this, it generates `GetHashCode`, `Equals`, `IEquatable`, and equality operators for all fields, + XML documentation.
1111
- `XML: Add Equality Methods to Properties`: Same as the one above, but for properties.
1212
- `XML: Add Equality Methods to Members`: Same as the one above, but for both Fields and Properties.
1313
- `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.
1415

15-
![Screenshot](media/Screenshot%202025-08-28%20074816.png)
16+
![Screenshot](media/Screenshot%202025-08-28%20133212.png)
1617

1718
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.
1819

@@ -31,73 +32,7 @@ public class Class1
3132
}
3233
```
3334

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-
public class Class1 : IEquatable<Class1>
39-
{
40-
public string Greeting { 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 <see langword="true"/>, indicates that <paramref name = "other"/> is equal to this instance, is of same type as this instance, and is not null.</returns>
48-
public override bool Equals(object? other)
49-
{
50-
return other is Class1 value && 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 <see langword="true"/>, indicates that <paramref name = "other"/> is equal to this instance.</returns>
58-
public bool Equals(Class1? other)
59-
{
60-
return this.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-
public override int GetHashCode()
68-
{
69-
var hashCode = new HashCode();
70-
hashCode.Add(this.Greeting);
71-
return hashCode.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><see langword="true"/> if the left parameter is same as the right parameter, otherwise <see langword="false"/>.</returns>
80-
public static bool operator ==(Class1 left, Class1 right)
81-
{
82-
return left.Equals(right);
83-
}
84-
85-
/// <summary>
86-
/// 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><see langword="true"/> if the left parameter is different compared to the right parameter, otherwise <see langword="false"/> if both are same.</returns>
91-
public static bool operator !=(Class1 left, Class1 right)
92-
{
93-
return !(left == right);
94-
}
95-
}
96-
```
97-
98-
Typing all of this would've took a while!
99-
100-
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.
10136

10237
```cs
10338
public class Class1
@@ -114,6 +49,11 @@ public class Class1
11449
}
11550
```
11651

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+
11757
# 🧱 Prerequisites
11858
AddWithXmlDoc supports all Visual Studio versions starting from Visual Studio 2022. You should have
11959
Visual Studio versions at least 2022 to use AddWithXmlDoc.

docs/docs.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
**Table of Contents**
2+
1. [Installation](#installation)
3+
- 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+
<a name="installation"></a>
11+
12+
# 1. Installation
13+
This clause describes how to install AddWithXmlDoc.
14+
15+
<a name="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+
<a name="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+
<a name="usage"></a>
26+
27+
# 2. Usage
28+
29+
<a name="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+
![Initial Code](../media/docs/InitialCode.png)
35+
36+
<a name="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+
![Code](../media/docs/GenerateField.png)
42+
43+
<a name="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!
47+
48+
![Code](../media/docs/InheritdocGenerateField.png)
-93 KB
Binary file not shown.
84.5 KB
Loading

media/docs/GenerateField.png

173 KB
Loading
133 KB
Loading

media/docs/InitialCode.png

64.5 KB
Loading

src/AddWithXmlDoc.ConsoleTest/Program.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212

1313
var type = parsed.GetRoot().DescendantNodes().OfType<TypeDeclarationSyntax>().First();
1414

15-
csharpLSC.AddEqualityMembersToFields.ProvideRootNode(type);
16-
csharpLSC.AddEqualityMembersToFields.Invoke((newNode) =>
17-
{
18-
Console.WriteLine("Equality to Fields:");
19-
Console.WriteLine(newNode.ToString());
20-
});
21-
22-
csharpLSC.AddEqualityMembersToProperties.ProvideRootNode(type);
23-
csharpLSC.AddEqualityMembersToProperties.Invoke((newNode) =>
24-
{
25-
Console.WriteLine("Equality to Properties:");
26-
Console.WriteLine(newNode.ToString());
27-
});
28-
2915
csharpLSC.AddEqualityMembersToMembers.ProvideRootNode(type);
3016
csharpLSC.AddEqualityMembersToMembers.Invoke((newNode) =>
3117
{
@@ -39,3 +25,11 @@
3925
Console.WriteLine("Parameterless Constructor:");
4026
Console.WriteLine(newNode.ToString());
4127
});
28+
29+
csharpLSC.AddEqualityMembersToMembers.UseInheritdocWherePossible = true;
30+
csharpLSC.AddEqualityMembersToMembers.ProvideRootNode(type);
31+
csharpLSC.AddEqualityMembersToMembers.Invoke((newNode) =>
32+
{
33+
Console.WriteLine("Inheritdoc Equality to Members:");
34+
Console.WriteLine(newNode.ToString());
35+
});

src/AddWithXmlDoc.Core/Abstractions/IXmlAdd.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public interface IXmlAdd
3939
/// </summary>
4040
/// <param name="del">Once the operation is complete, the new node is sent here.</param>
4141
void Invoke(NewNodeDelegate del);
42+
43+
/// <summary>
44+
/// Makes use of the &lt;inheritdoc cref="..." /&gt; element where possible. Default value: <see langword="false"/>.
45+
/// </summary>
46+
bool UseInheritdocWherePossible { get; set; }
4247
}

src/AddWithXmlDoc.Core/AddWithXmlDoc.Core.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
1616
<RepositoryUrl>https://github.com/winscripter/AddWithXmlDoc</RepositoryUrl>
1717
<PackageTags>VisualStudio;Visual Studio;Roslyn;C#;CSharp;Code;Generator;SourceGeneration;Source Generation</PackageTags>
18-
<AssemblyVersion>1.0.2.0</AssemblyVersion>
19-
<FileVersion>1.0.2.0</FileVersion>
18+
<AssemblyVersion>2.0.0.0</AssemblyVersion>
19+
<FileVersion>2.0.0.0</FileVersion>
2020
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2121
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
22-
<Version>1.0.2</Version>
22+
<Version>2.0.0</Version>
23+
<PackageReleaseNotes>Added inheritdoc support</PackageReleaseNotes>
2324
</PropertyGroup>
2425

2526
<ItemGroup>

0 commit comments

Comments
 (0)