Skip to content

Commit b0afbae

Browse files
linkdotnetegil
authored andcommitted
refactor: use early return and simplify call
1 parent 406068c commit b0afbae

2 files changed

Lines changed: 7 additions & 18 deletions

File tree

src/bunit.core/Rendering/RootRenderTree.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,9 @@ public RenderFragment Wrap(RenderFragment target)
9191
public int GetCountOf<TComponent>()
9292
where TComponent : IComponent
9393
{
94-
var result = 0;
9594
var countType = typeof(TComponent);
9695

97-
for (int i = 0; i < registrations.Count; i++)
98-
{
99-
if (countType == registrations[i].ComponentType)
100-
result++;
101-
}
102-
103-
return result;
96+
return registrations.Count(t => countType == t.ComponentType);
10497
}
10598

10699
private static RenderFragment<RenderFragment> CreateRenderFragmentBuilder<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>>? parameterBuilder)

src/bunit.core/Rendering/TestRenderer.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
157157
logger.LogNewRenderBatchReceived();
158158

159159
RenderCount++;
160-
160+
161161
var renderEvent = new RenderEvent(renderBatch, new RenderTreeFrameDictionary());
162162

163163
// removes disposed components
@@ -299,19 +299,15 @@ void FindComponentsInRenderTree(int componentId)
299299
IRenderedComponentBase<TComponent> GetOrCreateRenderedComponent<TComponent>(RenderTreeFrameDictionary framesCollection, int componentId, TComponent component)
300300
where TComponent : IComponent
301301
{
302-
IRenderedComponentBase<TComponent> result;
303-
304302
if (renderedComponents.TryGetValue(componentId, out var renderedComponent))
305303
{
306-
result = (IRenderedComponentBase<TComponent>)renderedComponent;
307-
}
308-
else
309-
{
310-
LoadRenderTreeFrames(componentId, framesCollection);
311-
result = activator.CreateRenderedComponent(componentId, component, framesCollection);
312-
renderedComponents.Add(result.ComponentId, result);
304+
return (IRenderedComponentBase<TComponent>)renderedComponent;
313305
}
314306

307+
LoadRenderTreeFrames(componentId, framesCollection);
308+
var result = activator.CreateRenderedComponent(componentId, component, framesCollection);
309+
renderedComponents.Add(result.ComponentId, result);
310+
315311
return result;
316312
}
317313

0 commit comments

Comments
 (0)