Skip to content

Community Post: C# 15 union types and closed hierarchies - #26207

Merged
fahrigedik merged 5 commits into
devfrom
EngincanV/dotnet-11-article
Sep 23, 2026
Merged

fahrigedik merged 5 commits into
devfrom
EngincanV/dotnet-11-article

Conversation

@EngincanV

Copy link
Copy Markdown
Member

No description provided.

@EngincanV
EngincanV requested review from enisn and a lite review from Copilot September 23, 2026 12:30
@github-actions

Copy link
Copy Markdown
Contributor

Images automagically compressed by Calibre's image-actions ✨

Compression reduced images by 73.4%, saving 660.4 KB.

Filename Before After Improvement Visual comparison
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/cover.png 521.9 KB 107.3 KB 79.4% View diff
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/test-results.png 146.5 KB 45.8 KB 68.7% View diff
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/union-vs-closed.png 76.4 KB 28.5 KB 62.7% View diff
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/refunded-build-errors.png 60.2 KB 23.1 KB 61.6% View diff
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/order-state-machine.png 47.3 KB 16.6 KB 64.9% View diff
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/choosing-a-model.png 47.8 KB 18.2 KB 61.9% View diff

@EngincanV
EngincanV requested review from fahrigedik and removed request for enisn September 23, 2026 12:32
@github-actions

Copy link
Copy Markdown
Contributor

Images automagically compressed by Calibre's image-actions ✨

Compression reduced images by 5.4%, saving 8.6 KB.

Filename Before After Improvement Visual comparison
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/cover.png 107.3 KB 101.7 KB 5.2% View diff
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/refunded-build-errors.png 23.1 KB 21.5 KB 6.9% View diff
docs/en/Community-Articles/2026-09-23-csharp-15-union-types-and-closed-hierarchies/union-vs-closed.png 28.5 KB 27.1 KB 5.1% View diff

3 images did not require optimisation.

@fahrigedik
fahrigedik merged commit d706979 into dev Sep 23, 2026
1 check passed
@fahrigedik
fahrigedik deleted the EngincanV/dotnet-11-article branch September 23, 2026 12:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved review findings include a critical architectural issue and an ambiguity in the reusable generic result example.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

This PR adds a Community Article on C# 15 union types, closed hierarchies, and ABP integration.

Changes:

  • Explains exhaustive state and result modeling.
  • Covers JSON serialization, caching, and versioning.
  • Provides API, generic-result, and migration guidance.
File Review summary
docs/​en/​Community-Articles/​2026-09-23-csharp-15-union-types-and-closed-hierarchies/​post.md Open findings cover a critical layering issue, generic-result conversion ambiguity, sample reproducibility, and closed-hierarchy wording.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Placing an order has four *expected* outcomes, and only one of them is a success. Running out of stock isn't exceptional in an online shop; it happens every day, and the caller must handle it. That's a perfect fit for the `PlaceOrderResult` union we declared earlier. The domain service returns cases directly, and the implicit conversion works even through `Task<PlaceOrderResult>`:

```csharp
public async Task<PlaceOrderResult> PlaceAsync(PlaceOrderInput input, CancellationToken cancellationToken = default)
Comment on lines +483 to +485
public static implicit operator Result<T>(T value) => new Success<T>(value);

public static implicit operator Result<T>(Error error) => new Failure<T>(error);
dotnet add test/OrderDemo.Tests package Microsoft.Extensions.TimeProvider.Testing
```

Then add the code from this article: the domain types, `Order`, `OrderPlacementService`, the in-memory stores, the API's `Program.cs` and DTOs, and the `Directory.Build.props` from the migration section. The API also needs `public partial class Program;` at the end of `Program.cs`, so that `WebApplicationFactory<Program>` can find it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants