Skip to content

Commit 4315da6

Browse files
authored
fix: Add OverloadResolutionAttribute for Render method in .NET 9.0+ (#1801)
1 parent e686527 commit 4315da6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to **bUnit** will be documented in this file. The project ad
88

99
### Added
1010

11+
- `Render(RenderFragment)` is preferred via the `OverloadResolutionAttribute`. Reported by [@ScarletKuro](https://github.com/ScarletKuro) in #1800. Fixed by [@linkdotnet](https://github.com/linkdotnet).
1112
- `FindByTestId` to `bunit.web.query` to gather elements by a given test id. By [@jimSampica](https://github.com/jimSampica)
1213

1314
## [2.4.2] - 2025-12-21

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)