Skip to content

Commit 0eab91b

Browse files
committed
fix: Add OverloadResolutionAttribute for Render method in .NET 9.0+
1 parent 55e2ef2 commit 0eab91b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `Render(RenderFragment)` is preferred via the `OverloadResolutionAttribute`. Reported by [@ScarletKuro](https://github.com/ScarletKuro) in #1800. Fixed by [@linkdotnet](https://github.com/linkdotnet).
12+
913
## [2.4.2] - 2025-12-21
1014

1115
### Fixed

src/bunit/BunitContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#if NET9_0_OR_GREATER
2+
using System.Runtime.CompilerServices;
3+
#endif
14
using Bunit.Extensions;
25
using Bunit.Rendering;
36
using Microsoft.Extensions.Logging;
@@ -158,9 +161,12 @@ public virtual IRenderedComponent<TComponent> Render<TComponent>(Action<Componen
158161
/// <typeparam name="TComponent">The type of component to find in the render tree.</typeparam>
159162
/// <param name="renderFragment">The render fragment to render.</param>
160163
/// <returns>The <see cref="RenderedComponent{TComponent}"/>.</returns>
164+
#if NET9_0_OR_GREATER
165+
[OverloadResolutionPriority(1)]
166+
#endif
161167
public virtual IRenderedComponent<TComponent> Render<TComponent>(RenderFragment renderFragment)
162168
where TComponent : IComponent
163-
=> this.RenderInsideRenderTree<TComponent>(renderFragment);
169+
=> RenderInsideRenderTree<TComponent>(renderFragment);
164170

165171
/// <summary>
166172
/// Renders the <paramref name="renderFragment"/> and returns it as a <see cref="IRenderedComponent{TComponent}"/>.

0 commit comments

Comments
 (0)