Skip to content

Commit

Permalink
Updated stylecop and threading analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-n committed Oct 20, 2023
1 parent 1a69fbf commit 6c5aa71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

<ItemGroup Label="commom configuration code style.">

<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.4.27">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
20 changes: 20 additions & 0 deletions src/GameLogic/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
}
}

/// <summary>
/// Executes the <paramref name="action"/> for each element of <paramref name="enumerable"/>.
/// </summary>
/// <typeparam name="T">The generic type of the enumerable.</typeparam>
/// <param name="enumerable">The enumerable.</param>
/// <param name="action">The action which should be executed for each element.</param>
/// <exception cref="System.ArgumentNullException">action.</exception>
public static async ValueTask ForEachAsync<T>(this IEnumerable<T> enumerable, Func<T, ValueTask> action)
{
if (action is null)
{
throw new ArgumentNullException(nameof(action));
}

foreach (var item in enumerable)
{
await action(item).ConfigureAwait(false);
}
}

/// <summary>
/// Returns the enumerable as list, by either casting it or creating it.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/GameLogic/ObserverToWorldViewAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async ValueTask LocateablesOutOfScopeAsync(IEnumerable<ILocateable> oldOb
oldItems.ForEach(item => this._observingObjects.Remove(item));
}

oldItems.ForEach(item => item.RemoveObserverAsync(this._adaptee));
await oldItems.ForEachAsync(item => item.RemoveObserverAsync(this._adaptee)).ConfigureAwait(false);

if (this._adaptee is IHasBucketInformation { NewBucket: null })
{
Expand Down Expand Up @@ -208,7 +208,7 @@ public async ValueTask NewLocateablesInScopeAsync(IEnumerable<ILocateable> newOb
await this._adaptee.InvokeViewPlugInAsync<IShowMoneyDropPlugIn>(p => p.ShowMoneyAsync(money.Id, false, money.Amount, money.Position)).ConfigureAwait(false);
}

newItems.ForEach(item => item.AddObserverAsync(this._adaptee));
await newItems.ForEachAsync(item => item.AddObserverAsync(this._adaptee)).ConfigureAwait(false);
}

/// <summary>
Expand Down

0 comments on commit 6c5aa71

Please sign in to comment.