Skip to content

Commit 5bcb67f

Browse files
BillWagnerCopilot
andauthored
Use snippets in article (#50263)
* Use snippets in article Responding to #50244 These files should remain in the repo, and should generally be included in the article * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 3aec531 commit 5bcb67f

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

docs/csharp/fundamentals/tutorials/snippets/xml-documentation/BankAccount.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ public string GetAccountHistory()
163163
return report.ToString();
164164
}
165165

166-
// Added for OO tutorial:
167-
168166
/// <summary>
169167
/// Performs month-end processing for the account. This virtual method can be overridden in derived classes
170168
/// to implement specific month-end behaviors such as interest calculations, fee assessments, or statement generation.

docs/csharp/fundamentals/tutorials/snippets/xml-documentation/GiftCardAccount.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
namespace OOProgramming;
22

3-
/// <summary>
4-
/// Represents a gift card account that extends <see cref="BankAccount"/> with optional recurring monthly deposits.
5-
/// Designed for prepaid gift cards that can optionally receive automatic monthly top-ups.
6-
/// </summary>
3+
/// <inheritdoc/>
74
/// <remarks>
85
/// A gift card account is a specialized prepaid account that can be loaded with an initial balance and optionally
96
/// configured to receive automatic monthly deposits. This account type is ideal for gift cards, allowances, or

docs/csharp/fundamentals/tutorials/snippets/xml-documentation/InterestEarningAccount.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
namespace OOProgramming;
22

3-
/// <summary>
4-
/// Represents an interest-earning bank account that extends <see cref="BankAccount"/> with monthly interest payments.
5-
/// Earns interest on balances above $500 at a rate of 2% annually, applied monthly.
6-
/// </summary>
3+
// <InterestEarningAccountComments>
4+
/// <inheritdoc/>
75
/// <remarks>
86
/// An interest-earning account is a specialized savings account that rewards customers for maintaining higher balances.
97
/// Interest is only earned when the account balance exceeds $500, encouraging customers to maintain substantial deposits.
108
/// The annual interest rate of 2% is applied monthly to qualifying balances, providing a simple savings incentive.
119
/// This account type uses the standard minimum balance of $0 from the base <see cref="BankAccount"/> class.
1210
/// </remarks>
1311
public class InterestEarningAccount : BankAccount
12+
// </InterestEarningAccountComments>
1413
{
1514
/// <summary>
1615
/// Initializes a new instance of the <see cref="InterestEarningAccount"/> class with the specified owner name and initial balance.

docs/csharp/fundamentals/tutorials/snippets/xml-documentation/LineOfCreditAccount.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
namespace OOProgramming;
22

3-
/// <summary>
4-
/// Represents a line of credit account that extends <see cref="BankAccount"/> with credit limit functionality.
5-
/// Allows negative balances up to a specified credit limit and applies monthly interest charges on outstanding balances.
6-
/// </summary>
3+
/// <inheritdoc/>
74
/// <remarks>
85
/// A line of credit account differs from a regular bank account in that it allows the balance to go negative
96
/// up to a predefined credit limit. When the balance is negative (indicating borrowed money), the account

docs/csharp/fundamentals/tutorials/xml-documentation.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Generate XML documentation from your source code
33
description: "Learn to add `///` comments that generate XML documentation directly from your source code. Learn which tags are available and how to add documentation blocks to types and members."
4-
ms.topic: tutorial #Don't change.
4+
ms.topic: tutorial
55
ms.date: 10/14/2025
66
ai-usage: ai-assisted
77
#customer intent: As a developer, I want to generate XML documentation comments so that other developers can use my code successfully.
@@ -50,7 +50,9 @@ Build the project now. You see warnings for any public members that are missing
5050
</doc>
5151
```
5252

53-
With the file in place, start adding targeted XML comments and immediately verify how each one appears in the generated output.
53+
With the file in place, start adding targeted XML comments and immediately verify how each one appears in the generated output. Start with the `Transaction` record type:
54+
55+
:::code language="csharp" source="./snippets/xml-documentation/transaction.cs":::
5456

5557
## Add documentation comments
5658

@@ -65,6 +67,10 @@ You now cycle through the build warnings to add concise, useful documentation to
6567
1. For methods that return a value, add `<returns>` with a short description of what callers receive. Avoid repeating the method name or managed type.
6668
1. Work with the `BankAccount` base class first.
6769

70+
Your version should look something like the following code:
71+
72+
:::code language="csharp" source="./snippets/xml-documentation/BankAccount.cs":::
73+
6874
When you're done, open the regenerated XML file and confirm that each member appears with your new elements. A trimmed portion might look like this:
6975

7076
```xml
@@ -83,19 +89,17 @@ When you're done, open the regenerated XML file and confirm that each member app
8389
8490
## Use `<inheritdoc/>` in derived classes
8591

86-
If you derive from `BankAccount` (for example, a `SavingsAccount` that applies interest), you can inherit base documentation instead of copying it. Add a self-closing `<inheritdoc/>` element inside the derived member's documentation block. You can still append more elements (such as extra `<remarks>` details) after `<inheritdoc/>` to document the specialized behavior.
92+
If you derive from `BankAccount` (for example, a `SavingsAccount` that applies interest), you can inherit base documentation instead of copying it. Add a self-closing `<inheritdoc/>` element inside the derived member's documentation block. You can still append more elements (such as extra `<remarks>` details) after `<inheritdoc/>` to document the specialized behavior:
8793

88-
```csharp
89-
/// <inheritdoc/>
90-
/// <remarks>Adds monthly interest during month-end processing.</remarks>
91-
public class SavingsAccount : BankAccount { /* ... */ }
92-
```
94+
:::code language="csharp" source="./snippets/xml-documentation/InterestEarningAccount.cs" id="InterestEarningAccountComments":::
9395

9496
> [!NOTE]
9597
> `<inheritdoc/>` reduces duplication and helps maintain consistency when you update base type documentation later.
9698
9799
After you finish documenting the public surface, build one final time to confirm there are no remaining CS1591 warnings. Your project now produces useful IntelliSense and a structured XML file ready for publishing workflows.
98100

101+
You can see the full annotated sample in [the source folder](https://github.com/dotnet/docs/tree/main/docs/csharp/fundamentals/tutorials/snippets/xml-documentation) of the [dotnet/docs](https://github.com/dotnet/docs) repository on GitHub.
102+
99103
## Build output from comments
100104

101105
You can explore more by trying any of these tools to create output from XML comments:

0 commit comments

Comments
 (0)