-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@typeparam TItem | ||
@{ | ||
int i = 0; | ||
foreach (TItem value in In ?? Enumerable.Empty<TItem>()) | ||
{ | ||
var item = new ValueWithIndex<TItem>(value!, i++); | ||
@ChildContent!(item); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Source/Lib/Morris.Blazor.ControlFlow/ForEachWithIndex.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using System.Collections.Generic; | ||
|
||
namespace Morris.Blazor.ControlFlow; | ||
|
||
public partial class ForEachWithIndex<TItem> | ||
{ | ||
#if NET6_0_OR_GREATER | ||
[EditorRequired] | ||
#endif | ||
[Parameter] public IEnumerable<TItem>? In { get; set; } | ||
#if NET6_0_OR_GREATER | ||
[EditorRequired] | ||
#endif | ||
[Parameter] public RenderFragment<ValueWithIndex<TItem>>? ChildContent { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Morris.Blazor.ControlFlow; | ||
|
||
public readonly struct ValueWithIndex<T> | ||
{ | ||
public T Value { get; } = default!; | ||
public int Index { get; } = 0; | ||
|
||
public ValueWithIndex(T value, int index) | ||
{ | ||
Index = index; | ||
Value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters