Skip to content

Commit f70ad08

Browse files
committed
Atualização de versão e adição de métodos na classe Problems
* Atualização de versão - Alterado `SPPreview` de `-preview-4.6` para `-preview-4.7`. * Melhoria na classe Problems - Adicionados métodos `ForEach(Action<Problem> action)` e `ForEach<T>(T param, Action<T, Problem> action)`. - Incluídas documentações XML para novos métodos, melhorando a legibilidade.
1 parent 577ff28 commit f70ad08

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111
<PropertyGroup>
1212
<SPVer>1.0.0</SPVer>
13-
<SPPreview>-preview-4.6</SPPreview>
13+
<SPPreview>-preview-4.7</SPPreview>
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<FluentValidationVer>12.0.0</FluentValidationVer>

src/RoyalCode.SmartProblems/Problems.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,64 @@ public InvalidOperationException ToException(string messagePattern, string separ
480480
return new InvalidOperationException(message);
481481
}
482482

483+
/// <summary>
484+
/// Execute the specified action for each problem in the collection.
485+
/// </summary>
486+
/// <param name="action">The action to execute for each problem.</param>
487+
/// <returns>
488+
/// The same instance of the collection, to allow method chaining.
489+
/// </returns>
490+
public Problems ForEach(Action<Problem> action)
491+
{
492+
ArgumentNullException.ThrowIfNull(action);
493+
494+
if (Count == 0)
495+
return this;
496+
497+
action(firstProblem!);
498+
499+
if (Count == 1)
500+
return this;
501+
502+
var current = head;
503+
while (current is not null)
504+
{
505+
action(current.Problem);
506+
current = current.Next;
507+
}
508+
509+
return this;
510+
}
511+
512+
/// <summary>
513+
/// Execute the specified action for each problem in the collection, passing an additional parameter.
514+
/// </summary>
515+
/// <typeparam name="T">The type of the additional parameter.</typeparam>
516+
/// <param name="param">The additional parameter to pass to the action.</param>
517+
/// <param name="action">The action to execute for each problem, with the additional parameter.</param>
518+
/// <returns>The same instance of the collection, to allow method chaining.</returns>
519+
public Problems ForEach<T>(T param, Action<T, Problem> action)
520+
{
521+
ArgumentNullException.ThrowIfNull(param);
522+
ArgumentNullException.ThrowIfNull(action);
523+
524+
if (Count == 0)
525+
return this;
526+
527+
action(param, firstProblem!);
528+
529+
if (Count == 1)
530+
return this;
531+
532+
var current = head;
533+
while (current is not null) {
534+
action(param, current.Problem);
535+
current = current.Next;
536+
}
537+
538+
return this;
539+
}
540+
483541
/// <summary>
484542
/// Convert the collection of problems to a <see cref="Result"/> instance.
485543
/// </summary>

0 commit comments

Comments
 (0)