Remove Do() and replace with foreach()

This commit is contained in:
tomas
2022-08-19 22:15:00 +02:00
committed by abcdefg30
parent 92478a219e
commit ac623d784a
6 changed files with 22 additions and 21 deletions

View File

@@ -38,12 +38,6 @@ namespace OpenRA
catch { return def; }
}
public static void Do<T>(this IEnumerable<T> e, Action<T> fn)
{
foreach (var ee in e)
fn(ee);
}
public static Lazy<T> Lazy<T>(Func<T> p) { return new Lazy<T>(p); }
public static IEnumerable<string> GetNamespaces(this Assembly a)

View File

@@ -85,7 +85,8 @@ namespace OpenRA.Mods.Cnc.Graphics
if (!cache.Any() || length != cachedLength || pos != cachedPos)
cache = GenerateRenderables(wr);
cache.Do(c => c.Render(wr));
foreach (var renderable in cache)
renderable.Render(wr);
}
public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }

View File

@@ -172,13 +172,13 @@ namespace OpenRA.Mods.Common.Traits
if (health.DamageState == DamageState.Undamaged)
{
Repairers.Do(r =>
foreach (var repairer in Repairers)
{
if (r == self.Owner)
if (repairer == self.Owner)
return;
r.PlayerActor.TraitOrDefault<PlayerExperience>()?.GiveExperience(Info.PlayerExperience);
});
repairer.PlayerActor.TraitOrDefault<PlayerExperience>()?.GiveExperience(Info.PlayerExperience);
}
Repairers.Clear();
RepairActive = false;

View File

@@ -95,14 +95,16 @@ namespace OpenRA.Mods.Common.Traits
}
// Add buildables that have a build limit set and are not already in the list
player.World.ActorsWithTrait<Buildable>()
.Where(a =>
a.Actor.Owner == player &&
a.Actor.IsInWorld &&
!a.Actor.IsDead &&
!ret.ContainsKey(a.Actor.Info.Name) &&
a.Actor.Info.TraitInfo<BuildableInfo>().BuildLimit > 0)
.Do(b => ret[b.Actor.Info.Name].Add(b.Actor));
var buildables = player.World.ActorsWithTrait<Buildable>()
.Where(a =>
a.Actor.Owner == player &&
a.Actor.IsInWorld &&
!a.Actor.IsDead &&
!ret.ContainsKey(a.Actor.Info.Name) &&
a.Actor.Info.TraitInfo<BuildableInfo>().BuildLimit > 0);
foreach (var buildable in buildables)
ret[buildable.Actor.Info.Name].Add(buildable.Actor);
return ret;
}

View File

@@ -343,7 +343,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
text: "Delete all maps on this page?",
onConfirm: () =>
{
maps.Do(m => DeleteMap(m));
foreach (var map in maps)
DeleteMap(map);
after?.Invoke(Game.ModData.MapCache.ChooseInitialMap(null, Game.CosmeticRandom));
},
confirmText: "Delete",

View File

@@ -463,7 +463,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
text: $"Delete {list.Count} replays?",
onConfirm: () =>
{
list.ForEach(DeleteReplay);
foreach (var replayMetadata in list)
DeleteReplay(replayMetadata);
if (selectedReplay == null)
SelectFirstVisibleReplay();
},