.Any(), .Count() -> .Count or .Length

This commit is contained in:
Eduardo Cáceres
2022-05-02 13:05:22 +02:00
committed by atlimit8
parent 6eb4fe8980
commit 79f321cb44
138 changed files with 233 additions and 258 deletions

View File

@@ -564,7 +564,7 @@ namespace OpenRA
fli.Field.SetValue(self, val);
}
if (missing.Any())
if (missing.Count > 0)
throw new MissingFieldsException(missing.ToArray());
}

View File

@@ -114,7 +114,7 @@ namespace OpenRA
OptionalDependencies = OptionalPrerequisitesOf(i).ToList()
}).ToList();
var resolved = source.Where(s => !s.Dependencies.Any() && !s.OptionalDependencies.Any()).ToList();
var resolved = source.Where(s => s.Dependencies.Count == 0 && s.OptionalDependencies.Count == 0).ToList();
var unresolved = source.Except(resolved);
var testResolve = new Func<Type, Type, bool>((a, b) => a == b || a.IsAssignableFrom(b));

View File

@@ -235,7 +235,7 @@ namespace OpenRA
static bool AnyCustomYaml(MiniYaml yaml)
{
return yaml != null && (yaml.Value != null || yaml.Nodes.Any());
return yaml != null && (yaml.Value != null || yaml.Nodes.Count > 0);
}
static bool AnyFlaggedTraits(ModData modData, List<MiniYamlNode> actors)

View File

@@ -223,7 +223,8 @@ namespace OpenRA.Graphics
ShadowAmbient, ShadowDiffuse, shadowPalette.TextureMidIndex, normals.TextureMidIndex);
}
}
}));
}
));
var screenLightVector = Util.MatrixVectorMultiply(invShadowTransform, ZVector);
screenLightVector = Util.MatrixVectorMultiply(cameraTransform, screenLightVector);

View File

@@ -130,13 +130,13 @@ namespace OpenRA
if (type == Type.NodeList)
{
var listValue = (List<MiniYamlNode>)value;
if (required || listValue.Any())
if (required || listValue.Count > 0)
nodes.Add(new MiniYamlNode(key, null, listValue));
}
else if (type == Type.MiniYaml)
{
var yamlValue = (MiniYaml)value;
if (required || (yamlValue != null && (yamlValue.Value != null || yamlValue.Nodes.Any())))
if (required || (yamlValue != null && (yamlValue.Value != null || yamlValue.Nodes.Count > 0)))
nodes.Add(new MiniYamlNode(key, yamlValue));
}
else
@@ -521,7 +521,7 @@ namespace OpenRA
while (true)
{
temp = new MPos(temp.U, temp.V - 1);
if (!inverseCellProjection.Contains(temp) || inverseCellProjection[temp].Any())
if (!inverseCellProjection.Contains(temp) || inverseCellProjection[temp].Count > 0)
break;
projectedHeight[temp] = height;
@@ -534,7 +534,7 @@ namespace OpenRA
while (inverseCellProjection.Contains((MPos)puv))
{
var inverse = inverseCellProjection[(MPos)puv];
if (inverse.Any())
if (inverse.Count > 0)
{
// The original games treat the top of cliffs the same way as the bottom
// This information isn't stored in the map data, so query the offset from the tileset
@@ -725,10 +725,10 @@ namespace OpenRA
{
var allTop = Unproject(new PPos(x, Bounds.Top));
var allBottom = Unproject(new PPos(x, Bounds.Bottom));
if (allTop.Any())
if (allTop.Count > 0)
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
if (allBottom.Any())
if (allBottom.Count > 0)
bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V);
}
}
@@ -1135,7 +1135,7 @@ namespace OpenRA
// Project this guessed cell and take the first available cell
// If it is projected outside the layer, then make another guess.
var allProjected = ProjectedCellsCovering(uv);
var projected = allProjected.Any() ? allProjected.First()
var projected = allProjected.Length > 0 ? allProjected.First()
: new PPos(uv.U, uv.V.Clamp(Bounds.Top, Bounds.Bottom));
// Clamp the projected cell to the map area
@@ -1145,7 +1145,7 @@ namespace OpenRA
// This may fail if the projected cell covered a cliff or another feature
// where there is a large change in terrain height.
var unProjected = Unproject(projected);
if (!unProjected.Any())
if (unProjected.Count == 0)
{
// Adjust V until we find a cell that works
for (var x = 2; x <= 2 * Grid.MaximumTerrainHeight; x++)
@@ -1156,12 +1156,12 @@ namespace OpenRA
continue;
unProjected = Unproject(test);
if (unProjected.Any())
if (unProjected.Count > 0)
break;
}
// This shouldn't happen. But if it does, return the original value and hope the caller doesn't explode.
if (!unProjected.Any())
if (unProjected.Count == 0)
{
Log.Write("debug", "Failed to clamp map cell {0} to map bounds", uv);
return uv;
@@ -1187,7 +1187,7 @@ namespace OpenRA
cells = Unproject(new PPos(u, v));
}
while (!cells.Any());
while (cells.Count == 0);
return cells.Random(rand).ToCPos(Grid.Type);
}
@@ -1202,7 +1202,7 @@ namespace OpenRA
var allProjected = ProjectedCellsCovering(uv);
PPos edge;
if (allProjected.Any())
if (allProjected.Length > 0)
{
var puv = allProjected.First();
var horizontalBound = ((puv.U - Bounds.Left) < Bounds.Width / 2) ? Bounds.Left : Bounds.Right;
@@ -1217,7 +1217,7 @@ namespace OpenRA
edge = new PPos(Bounds.Left, Bounds.Top);
var unProjected = Unproject(edge);
if (!unProjected.Any())
if (unProjected.Count == 0)
{
// Adjust V until we find a cell that works
for (var x = 2; x <= 2 * Grid.MaximumTerrainHeight; x++)
@@ -1228,12 +1228,12 @@ namespace OpenRA
continue;
unProjected = Unproject(test);
if (unProjected.Any())
if (unProjected.Count > 0)
break;
}
// This shouldn't happen. But if it does, return the original value and hope the caller doesn't explode.
if (!unProjected.Any())
if (unProjected.Count == 0)
{
Log.Write("debug", "Failed to find closest edge for map cell {0}", uv);
return uv;
@@ -1256,22 +1256,22 @@ namespace OpenRA
for (var u = Bounds.Left; u < Bounds.Right; u++)
{
unProjected = Unproject(new PPos(u, Bounds.Top));
if (unProjected.Any())
if (unProjected.Count > 0)
edgeCells.Add(unProjected.MinBy(x => x.V).ToCPos(Grid.Type));
unProjected = Unproject(new PPos(u, bottom));
if (unProjected.Any())
if (unProjected.Count > 0)
edgeCells.Add(unProjected.MaxBy(x => x.V).ToCPos(Grid.Type));
}
for (var v = Bounds.Top; v < Bounds.Bottom; v++)
{
unProjected = Unproject(new PPos(Bounds.Left, v));
if (unProjected.Any())
if (unProjected.Count > 0)
edgeCells.Add((v == bottom ? unProjected.MaxBy(x => x.V) : unProjected.MinBy(x => x.V)).ToCPos(Grid.Type));
unProjected = Unproject(new PPos(Bounds.Right - 1, v));
if (unProjected.Any())
if (unProjected.Count > 0)
edgeCells.Add((v == bottom ? unProjected.MaxBy(x => x.V) : unProjected.MinBy(x => x.V)).ToCPos(Grid.Type));
}

View File

@@ -133,7 +133,7 @@ namespace OpenRA
}
var sources = files.Select(s => MiniYaml.FromStream(fileSystem.Open(s), s).Where(IsLoadableRuleDefinition).ToList());
if (RuleDefinitions.Nodes.Any())
if (RuleDefinitions.Nodes.Count > 0)
sources = sources.Append(RuleDefinitions.Nodes.Where(IsLoadableRuleDefinition).ToList());
var yamlNodes = MiniYaml.Merge(sources);

View File

@@ -472,7 +472,7 @@ namespace OpenRA
}
var yaml = files.Select(s => FromStream(fileSystem.Open(s), s));
if (mapRules != null && mapRules.Nodes.Any())
if (mapRules != null && mapRules.Nodes.Count > 0)
yaml = yaml.Append(mapRules.Nodes);
return Merge(yaml);

View File

@@ -227,7 +227,7 @@ namespace OpenRA.Network
ModWebsite = manifest.Metadata.Website;
ModIcon32 = manifest.Metadata.WebIcon32;
Protected = !string.IsNullOrEmpty(server.Settings.Password);
Authentication = server.Settings.RequireAuthentication || server.Settings.ProfileIDWhitelist.Any();
Authentication = server.Settings.RequireAuthentication || server.Settings.ProfileIDWhitelist.Length > 0;
Clients = server.LobbyInfo.Clients.Select(c => new GameClient(c)).ToArray();
DisabledSpawnPoints = server.LobbyInfo.DisabledSpawnPoints?.ToArray() ?? Array.Empty<int>();
}

View File

@@ -193,7 +193,7 @@ namespace OpenRA.Network
var properties = type.GetProperties(Flags).Where(pi => pi.HasAttribute<SyncAttribute>());
foreach (var prop in properties)
if (!prop.CanRead || prop.GetIndexParameters().Any())
if (!prop.CanRead || prop.GetIndexParameters().Length > 0)
throw new InvalidOperationException(
"Properties using the Sync attribute must be readable and must not use index parameters.\n" +
"Invalid Property: " + prop.DeclaringType.FullName + "." + prop.Name);

View File

@@ -113,7 +113,7 @@ namespace OpenRA
?? selectableFactions.Random(playerRandom);
// Don't loop infinite
for (var i = 0; i <= 10 && selected.RandomFactionMembers.Any(); i++)
for (var i = 0; i <= 10 && selected.RandomFactionMembers.Count > 0; i++)
{
var faction = selected.RandomFactionMembers.Random(playerRandom);
selected = selectableFactions.FirstOrDefault(f => f.InternalName == faction);

View File

@@ -377,7 +377,7 @@ namespace OpenRA
public void EnableScissor(Rectangle rect)
{
// Must remain inside the current scissor rect
if (scissorState.Any())
if (scissorState.Count > 0)
rect = Rectangle.Intersect(rect, scissorState.Peek());
Flush();
@@ -405,7 +405,7 @@ namespace OpenRA
if (renderType == RenderType.World)
{
// Restore previous scissor rect
if (scissorState.Any())
if (scissorState.Count > 0)
{
var rect = scissorState.Peek();
var r = Rectangle.FromLTRB(
@@ -421,7 +421,7 @@ namespace OpenRA
else
{
// Restore previous scissor rect
if (scissorState.Any())
if (scissorState.Count > 0)
{
var rect = scissorState.Peek();
Context.EnableScissor(rect.X, rect.Y, rect.Width, rect.Height);

View File

@@ -635,9 +635,9 @@ namespace OpenRA.Server
events.Add(new CallbackEvent(() =>
{
var notAuthenticated = Type == ServerType.Dedicated && profile == null && (Settings.RequireAuthentication || Settings.ProfileIDWhitelist.Any());
var notAuthenticated = Type == ServerType.Dedicated && profile == null && (Settings.RequireAuthentication || Settings.ProfileIDWhitelist.Length > 0);
var blacklisted = Type == ServerType.Dedicated && profile != null && Settings.ProfileIDBlacklist.Contains(profile.ProfileID);
var notWhitelisted = Type == ServerType.Dedicated && Settings.ProfileIDWhitelist.Any() &&
var notWhitelisted = Type == ServerType.Dedicated && Settings.ProfileIDWhitelist.Length > 0 &&
(profile == null || !Settings.ProfileIDWhitelist.Contains(profile.ProfileID));
if (notAuthenticated)
@@ -663,7 +663,7 @@ namespace OpenRA.Server
}
else
{
if (Type == ServerType.Dedicated && (Settings.RequireAuthentication || Settings.ProfileIDWhitelist.Any()))
if (Type == ServerType.Dedicated && (Settings.RequireAuthentication || Settings.ProfileIDWhitelist.Length > 0))
{
Log.Write("server", $"Rejected connection from {newConn.EndPoint}; Not authenticated.");
SendOrderTo(newConn, "ServerError", RequiresForumAccount);

View File

@@ -306,7 +306,7 @@ namespace OpenRA.Support
public static AssemblyLoadContextBuilder AddDependencyContext(this AssemblyLoadContextBuilder builder, DependencyContext dependencyContext)
{
var ridGraph = dependencyContext.RuntimeGraph.Any()
var ridGraph = dependencyContext.RuntimeGraph.Count > 0
? dependencyContext.RuntimeGraph
: DependencyContext.Default.RuntimeGraph;

View File

@@ -217,7 +217,7 @@ namespace OpenRA.Traits
return Renderables;
}
public bool HasRenderables => !Shrouded && Renderables.Any();
public bool HasRenderables => !Shrouded && Renderables.Length > 0;
public override string ToString()
{

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Traits
void ITick.Tick(Actor self)
{
if (shakeEffects.Any())
if (shakeEffects.Count > 0)
{
worldRenderer.Viewport.Scroll(GetScrollOffset(), true);
shakeEffects.RemoveAll(t => t.ExpiryTime == ticks);

View File

@@ -38,7 +38,7 @@ namespace OpenRA
public Translation(string language, string[] translations, IReadOnlyFileSystem fileSystem)
{
if (translations == null || !translations.Any())
if (translations == null || translations.Length == 0)
return;
messageContexts = GetMessageContext(language, translations, fileSystem).ToList();

View File

@@ -270,7 +270,7 @@ namespace OpenRA.Widgets
public void PostInit(WidgetArgs args)
{
if (!Logic.Any())
if (Logic.Length == 0)
return;
args["widget"] = this;