Fix CA1825 warnings on empty array initialisation.

This commit is contained in:
Matthias Mailänder
2021-12-05 13:26:40 +01:00
committed by abcdefg30
parent 727084c5fc
commit 07815143f1
85 changed files with 171 additions and 117 deletions

View File

@@ -322,7 +322,7 @@ namespace OpenRA
// Special case handling of Game.Mod argument: if it matches a real filesystem path
// then we use this to override the mod search path, and replace it with the mod id
var modID = args.GetValue("Game.Mod", null);
var explicitModPaths = new string[0];
var explicitModPaths = Array.Empty<string>();
if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
{
explicitModPaths = new[] { modID };

View File

@@ -36,7 +36,7 @@ namespace OpenRA.GameRules
public class WarheadArgs
{
public WeaponInfo Weapon;
public int[] DamageModifiers = { };
public int[] DamageModifiers = Array.Empty<int>();
public WPos? Source;
public WRot ImpactOrientation;
public WPos ImpactPosition;

View File

@@ -80,10 +80,10 @@ namespace OpenRA
public readonly IReadOnlyDictionary<string, string> MapFolders;
public readonly MiniYaml LoadScreen;
public readonly string[] SoundFormats = { };
public readonly string[] SpriteFormats = { };
public readonly string[] PackageFormats = { };
public readonly string[] VideoFormats = { };
public readonly string[] SoundFormats = Array.Empty<string>();
public readonly string[] SpriteFormats = Array.Empty<string>();
public readonly string[] PackageFormats = Array.Empty<string>();
public readonly string[] VideoFormats = Array.Empty<string>();
readonly string[] reservedModuleNames =
{
@@ -208,7 +208,7 @@ namespace OpenRA
static string[] YamlList(Dictionary<string, MiniYaml> yaml, string key, bool parsePaths = false)
{
if (!yaml.ContainsKey(key))
return new string[] { };
return Array.Empty<string>();
return yaml[key].ToDictionary().Keys.ToArray();
}

View File

@@ -270,7 +270,7 @@ namespace OpenRA
// Take the SHA1
if (streams.Count == 0)
return CryptoUtil.SHA1Hash(new byte[0]);
return CryptoUtil.SHA1Hash(Array.Empty<byte>());
var merged = streams[0];
for (var i = 1; i < streams.Count; i++)
@@ -471,7 +471,7 @@ namespace OpenRA
foreach (var cell in AllCells)
{
var uv = cell.ToMPos(Grid.Type);
cellProjection[uv] = new PPos[0];
cellProjection[uv] = Array.Empty<PPos>();
inverseCellProjection[uv] = new List<MPos>(1);
}
@@ -973,7 +973,7 @@ namespace OpenRA
return (PPos)CellContaining(projectedPos).ToMPos(Grid.Type);
}
static readonly PPos[] NoProjectedCells = { };
static readonly PPos[] NoProjectedCells = Array.Empty<PPos>();
public PPos[] ProjectedCellsCovering(MPos uv)
{
if (!initializedCellProjection)

View File

@@ -54,7 +54,7 @@ namespace OpenRA
public readonly string[] categories;
public readonly int players;
public readonly Rectangle bounds;
public readonly short[] spawnpoints = { };
public readonly short[] spawnpoints = Array.Empty<short>();
public readonly MapGridType map_grid_type;
public readonly string minimap;
public readonly bool downloading;
@@ -160,7 +160,7 @@ namespace OpenRA
}
}
static readonly CPos[] NoSpawns = { };
static readonly CPos[] NoSpawns = Array.Empty<CPos>();
readonly MapCache cache;
readonly ModData modData;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Primitives;
namespace OpenRA
@@ -53,8 +54,8 @@ namespace OpenRA
public bool LockHandicap = false;
public int Handicap = 0;
public string[] Allies = { };
public string[] Enemies = { };
public string[] Allies = Array.Empty<string>();
public string[] Enemies = Array.Empty<string>();
public PlayerReference() { }
public PlayerReference(MiniYaml my) { FieldLoader.Load(this, my); }

View File

@@ -52,7 +52,7 @@ namespace OpenRA
public ModData(Manifest mod, InstalledMods mods, bool useLoadScreen = false)
{
Languages = new string[0];
Languages = Array.Empty<string>();
// Take a local copy of the manifest
Manifest = new Manifest(mod.Id, mod.Package);

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Network
// Loaded from file and updated during gameplay
public int LastOrdersFrame { get; private set; }
public int LastSyncFrame { get; private set; }
byte[] lastSyncPacket = new byte[0];
byte[] lastSyncPacket = Array.Empty<byte>();
// Loaded from file or set on game start
public Session.Global GlobalSettings { get; private set; }
@@ -95,7 +95,7 @@ namespace OpenRA.Network
public Dictionary<int, MiniYaml> TraitData = new Dictionary<int, MiniYaml>();
// Set on game start
int[] clientsBySlotIndex = { };
int[] clientsBySlotIndex = Array.Empty<int>();
int firstBotSlotIndex = -1;
public GameSave()

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Network
public readonly GameClient[] Clients;
/// <summary>The list of spawnpoints that are disabled for this game</summary>
public readonly int[] DisabledSpawnPoints = { };
public readonly int[] DisabledSpawnPoints = Array.Empty<int>();
public string ModLabel => $"{ModTitle} ({Version})";

View File

@@ -141,7 +141,7 @@ namespace OpenRA
public object CreateBasic(Type type)
{
return type.GetConstructor(new Type[0]).Invoke(new object[0]);
return type.GetConstructor(Array.Empty<Type>()).Invoke(Array.Empty<object>());
}
public object CreateUsingArgs(ConstructorInfo ctor, Dictionary<string, object> args)

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Traits
return info.SelectionPriority(modifiers) - (long)pixelDistance << 16;
}
static readonly Actor[] NoActors = { };
static readonly Actor[] NoActors = Array.Empty<Actor>();
public static IEnumerable<Actor> SubsetWithHighestSelectionPriority(this IEnumerable<Actor> actors, Modifiers modifiers)
{

View File

@@ -66,16 +66,16 @@ namespace OpenRA
public string Map = null;
[Desc("Takes a comma separated list of IP addresses that are not allowed to join.")]
public string[] Ban = { };
public string[] Ban = Array.Empty<string>();
[Desc("For dedicated servers only, allow anonymous clients to join.")]
public bool RequireAuthentication = false;
[Desc("For dedicated servers only, if non-empty, only allow authenticated players with these profile IDs to join.")]
public int[] ProfileIDWhitelist = { };
public int[] ProfileIDWhitelist = Array.Empty<int>();
[Desc("For dedicated servers only, if non-empty, always reject players with these user IDs from joining.")]
public int[] ProfileIDBlacklist = { };
public int[] ProfileIDBlacklist = Array.Empty<int>();
[Desc("For dedicated servers only, controls whether a game can be started with just one human player in the lobby.")]
public bool EnableSingleplayer = false;
@@ -227,7 +227,7 @@ namespace OpenRA
public string Name = "Commander";
public Color Color = Color.FromArgb(200, 32, 32);
public string LastServer = "localhost:1234";
public Color[] CustomColors = { };
public Color[] CustomColors = Array.Empty<Color>();
public string Language = "en";
}

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Traits
public enum TargetType : byte { Invalid, Actor, Terrain, FrozenActor }
public readonly struct Target
{
public static readonly Target[] None = { };
public static readonly Target[] None = Array.Empty<Target>();
public static readonly Target Invalid = default(Target);
readonly TargetType type;
@@ -175,7 +175,7 @@ namespace OpenRA.Traits
}
// Positions available to target for range checks
static readonly WPos[] NoPositions = { };
static readonly WPos[] NoPositions = Array.Empty<WPos>();
public IEnumerable<WPos> Positions
{
get

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Traits;
@@ -18,7 +19,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
public class WithHarvesterSpriteBodyInfo : WithFacingSpriteBodyInfo, Requires<HarvesterInfo>
{
[Desc("Images switched between depending on fullness of harvester. Overrides RenderSprites.Image.")]
public readonly string[] ImageByFullness = { };
public readonly string[] ImageByFullness = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new WithHarvesterSpriteBody(init, this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
@@ -23,7 +24,7 @@ namespace OpenRA.Mods.Common.Activities
public readonly string ToActor;
public CVec Offset = CVec.Zero;
public WAngle Facing = new WAngle(384);
public string[] Sounds = { };
public string[] Sounds = Array.Empty<string>();
public string Notification = null;
public int ForceHealthPercentage = 0;
public bool SkipMakeAnims = false;

View File

@@ -9,11 +9,13 @@
*/
#endregion
using System;
namespace OpenRA
{
public class AssetBrowser : IGlobalModData
{
[FieldLoader.Require]
public readonly string[] SupportedExtensions = new string[0];
public readonly string[] SupportedExtensions = Array.Empty<string>();
}
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
@@ -19,7 +20,7 @@ namespace OpenRA.Mods.Common.Effects
{
public class RevealShroudEffect : IEffect
{
static readonly PPos[] NoCells = { };
static readonly PPos[] NoCells = Array.Empty<PPos>();
readonly WPos pos;
readonly Player player;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -21,8 +22,8 @@ namespace OpenRA
public class ModPackage
{
public readonly string Title;
public readonly string[] TestFiles = { };
public readonly string[] Sources = { };
public readonly string[] TestFiles = Array.Empty<string>();
public readonly string[] Sources = Array.Empty<string>();
public readonly bool Required;
public readonly string Download;
@@ -106,21 +107,21 @@ namespace OpenRA
}
[FieldLoader.LoadUsing(nameof(LoadDownloads))]
public readonly string[] Downloads = { };
public readonly string[] Downloads = Array.Empty<string>();
static object LoadDownloads(MiniYaml yaml)
{
var downloadNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Downloads");
return downloadNode != null ? downloadNode.Value.Nodes.Select(n => n.Key).ToArray() : new string[0];
return downloadNode != null ? downloadNode.Value.Nodes.Select(n => n.Key).ToArray() : Array.Empty<string>();
}
[FieldLoader.LoadUsing(nameof(LoadSources))]
public readonly string[] Sources = { };
public readonly string[] Sources = Array.Empty<string>();
static object LoadSources(MiniYaml yaml)
{
var sourceNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Sources");
return sourceNode != null ? sourceNode.Value.Nodes.Select(n => n.Key).ToArray() : new string[0];
return sourceNode != null ? sourceNode.Value.Nodes.Select(n => n.Key).ToArray() : Array.Empty<string>();
}
}
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
@@ -24,16 +25,16 @@ namespace OpenRA.Mods.Common.Traits
public readonly PlayerRelationship ValidRelationships = PlayerRelationship.Ally;
[Desc("Play a randomly selected sound from this list when accepting cash.")]
public readonly string[] Sounds = { };
public readonly string[] Sounds = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new AcceptsDeliveredCash(init.Self, this); }
public override object Create(ActorInitializer init) { return new AcceptsDeliveredCash(this); }
}
public class AcceptsDeliveredCash : INotifyCashTransfer
{
readonly AcceptsDeliveredCashInfo info;
public AcceptsDeliveredCash(Actor self, AcceptsDeliveredCashInfo info)
public AcceptsDeliveredCash(AcceptsDeliveredCashInfo info)
{
this.info = info;
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -35,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
public abstract class AffectsShroud : ConditionalTrait<AffectsShroudInfo>, ISync, INotifyAddedToWorld,
INotifyRemovedFromWorld, INotifyMoving, INotifyCenterPositionChanged, ITick
{
static readonly PPos[] NoCells = { };
static readonly PPos[] NoCells = Array.Empty<PPos>();
readonly HashSet<PPos> footprint;

View File

@@ -139,10 +139,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly WDist AltitudeVelocity = new WDist(43);
[Desc("Sounds to play when the actor is taking off.")]
public readonly string[] TakeoffSounds = { };
public readonly string[] TakeoffSounds = Array.Empty<string>();
[Desc("Sounds to play when the actor is landing.")]
public readonly string[] LandingSounds = { };
public readonly string[] LandingSounds = Array.Empty<string>();
[Desc("The distance of the resupply base that the aircraft will wait for its turn.")]
public readonly WDist WaitDistanceFromResupplyBase = new WDist(3072);

View File

@@ -41,10 +41,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Muzzle position relative to turret or body, (forward, right, up) triples.",
"If weapon Burst = 1, it cycles through all listed offsets, otherwise the offset corresponding to current burst is used.")]
public readonly WVec[] LocalOffset = { };
public readonly WVec[] LocalOffset = Array.Empty<WVec>();
[Desc("Muzzle yaw relative to turret or body.")]
public readonly WAngle[] LocalYaw = { };
public readonly WAngle[] LocalYaw = Array.Empty<WAngle>();
[Desc("Move the turret backwards when firing.")]
public readonly WDist Recoil = WDist.Zero;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
@@ -20,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
"This can be prefixed with ! to invert the prerequisite (disabling production if the prerequisite is available)",
"and/or ~ to hide the actor from the production palette if the prerequisite is not available.",
"Prerequisites are granted by actors with the ProvidesPrerequisite trait.")]
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
[Desc("Production queue(s) that can produce this.")]
public readonly HashSet<string> Queue = new HashSet<string>();

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
@@ -24,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string[] Types = { "GroundLevelBridge" };
[Desc("Offsets to look for adjacent bridges to act on")]
public readonly CVec[] NeighbourOffsets = { };
public readonly CVec[] NeighbourOffsets = Array.Empty<CVec>();
[Desc("Delay between each segment repair step")]
public readonly int RepairPropagationDelay = 20;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -25,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Actor type to replace with on repair.")]
public readonly string ReplaceWithActor = null;
public readonly CVec[] NeighbourOffsets = { };
public readonly CVec[] NeighbourOffsets = Array.Empty<CVec>();
public override object Create(ActorInitializer init) { return new BridgePlaceholder(init.Self, this); }
}

View File

@@ -56,9 +56,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Clear smudges from underneath the building footprint on transform.")]
public readonly bool RemoveSmudgesOnTransform = true;
public readonly string[] BuildSounds = { };
public readonly string[] BuildSounds = Array.Empty<string>();
public readonly string[] UndeploySounds = { };
public readonly string[] UndeploySounds = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new Building(init, this); }

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Primitives;
@@ -23,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Type = "GroundLevelBridge";
public readonly CVec[] NeighbourOffsets = { };
public readonly CVec[] NeighbourOffsets = Array.Empty<CVec>();
[WeaponReference]
[Desc("The name of the weapon to use when demolishing the bridge")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Orders;
@@ -38,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("List of production queues for which the primary flag should be set.",
"If empty, the list given in the `Produces` property of the `" + nameof(Production) + "` trait will be used.")]
public readonly string[] ProductionQueues = { };
public readonly string[] ProductionQueues = Array.Empty<string>();
[CursorReference]
[Desc("Cursor to display when setting the primary building.")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects;
@@ -42,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool IsPlayerPalette = true;
[Desc("A list of 0 or more offsets defining the initial rally point path.")]
public readonly CVec[] Path = { };
public readonly CVec[] Path = Array.Empty<CVec>();
[NotificationReference("Speech")]
[Desc("The speech notification to play when setting a new rallypoint.")]

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly HashSet<string> Types = new HashSet<string>();
[Desc("A list of actor types that are initially spawned into this actor.")]
public readonly string[] InitialUnits = { };
public readonly string[] InitialUnits = Array.Empty<string>();
[Desc("When this actor is sold should all of its passengers be unloaded?")]
public readonly bool EjectOnSell = true;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Traits;
@@ -24,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Bot types that trigger the condition.")]
public readonly string[] Bots = { };
public readonly string[] Bots = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new GrantConditionOnBotOwner(init, this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -22,10 +23,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Condition = null;
[Desc("Play a random sound from this list when enabled.")]
public readonly string[] EnabledSounds = { };
public readonly string[] EnabledSounds = Array.Empty<string>();
[Desc("Play a random sound from this list when disabled.")]
public readonly string[] DisabledSounds = { };
public readonly string[] DisabledSounds = Array.Empty<string>();
[Desc("Levels of damage at which to grant the condition.")]
public readonly DamageState ValidDamageStates = DamageState.Heavy | DamageState.Critical;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -22,10 +23,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Condition = null;
[Desc("Play a random sound from this list when enabled.")]
public readonly string[] EnabledSounds = { };
public readonly string[] EnabledSounds = Array.Empty<string>();
[Desc("Play a random sound from this list when disabled.")]
public readonly string[] DisabledSounds = { };
public readonly string[] DisabledSounds = Array.Empty<string>();
[Desc("Minimum level of health at which to grant the condition.")]
public readonly int MinHP = 0;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Traits;
@@ -24,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("List of required prerequisites.")]
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new GrantConditionOnPrerequisite(init.Self, this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Traits;
@@ -23,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Terrain names to trigger the condition.")]
public readonly string[] TerrainTypes = { };
public readonly string[] TerrainTypes = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new GrantConditionOnTerrain(init, this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Traits;
@@ -23,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Tile set IDs to trigger the condition.")]
public readonly string[] TileSets = { };
public readonly string[] TileSets = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new GrantConditionOnTileSet(this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Traits;
@@ -42,11 +43,11 @@ namespace OpenRA.Mods.Common.Traits
public readonly int TimeDelay = 0;
[Desc("Only allow this crate action when the collector has these prerequisites")]
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
[ActorReference]
[Desc("Actor types that this crate action will not occur for.")]
public string[] ExcludedActorTypes = { };
public string[] ExcludedActorTypes = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new CrateAction(init.Self, this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
[ActorReference]
[FieldLoader.Require]
[Desc("The list of units to spawn.")]
public readonly string[] Units = { };
public readonly string[] Units = Array.Empty<string>();
[Desc("Factions that are allowed to trigger this action.")]
public readonly HashSet<string> ValidFactions = new HashSet<string>();

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -30,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Terrain types where the actor will take damage.")]
public readonly string[] Terrain = { };
public readonly string[] Terrain = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new DamagedByTerrain(this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
@@ -30,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Type = null;
[Desc("Sound to play when delivering cash")]
public readonly string[] Sounds = { };
public readonly string[] Sounds = Array.Empty<string>();
[CursorReference]
[Desc("Cursor to display when hovering over a valid actor to deliver cash to.")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Multiplier = 100;
[Desc("Only apply this cost change if owner has these prerequisites.")]
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
[Desc("Queues that this cost will apply.")]
public readonly HashSet<string> Queue = new HashSet<string>();

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Multiplier = 100;
[Desc("Only apply this time change if owner has these prerequisites.")]
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
[Desc("Queues that this time will apply.")]
public readonly HashSet<string> Queue = new HashSet<string>();

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Primitives;
@@ -32,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Remap these indices to player colors.")]
public readonly int[] RemapIndex = { };
public readonly int[] RemapIndex = Array.Empty<int>();
[Desc("Allow palette modifiers to change the palette.")]
public readonly bool AllowModifiers = true;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -28,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Name = "resources";
[Desc("Remap these indices to pre-defined colors.")]
public readonly int[] RemapIndex = { };
public readonly int[] RemapIndex = Array.Empty<int>();
[Desc("The fixed color to remap.")]
public readonly Color Color;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using OpenRA.Graphics;
@@ -32,11 +33,11 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Indices from BasePalette to be swapped with ReplaceIndex.")]
public readonly int[] Index = { };
public readonly int[] Index = Array.Empty<int>();
[FieldLoader.Require]
[Desc("Indices from BasePalette to replace from Index.")]
public readonly int[] ReplaceIndex = { };
public readonly int[] ReplaceIndex = Array.Empty<int>();
[Desc("Allow palette modifiers to change the palette.")]
public readonly bool AllowModifiers = true;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Primitives;
@@ -29,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string BaseName = "player";
[Desc("Remap these indices to player colors.")]
public readonly int[] RemapIndex = { };
public readonly int[] RemapIndex = Array.Empty<int>();
[Desc("Allow palette modifiers to change the palette.")]
public readonly bool AllowModifiers = true;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.FileSystem;
using OpenRA.Graphics;
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int[] TransparentIndex = { 0 };
[Desc("Map listed indices to shadow. Ignores previous color.")]
public readonly int[] ShadowIndex = { };
public readonly int[] ShadowIndex = Array.Empty<int>();
public readonly bool AllowModifiers = true;

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Filename = null;
[Desc("Map listed indices to shadow. Ignores previous color.")]
public readonly int[] ShadowIndex = { };
public readonly int[] ShadowIndex = Array.Empty<int>();
public readonly bool AllowModifiers = true;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -28,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string BaseName = "player";
[Desc("Remap these indices to player colors.")]
public readonly int[] RemapIndex = { };
public readonly int[] RemapIndex = Array.Empty<int>();
[Desc("Allow palette modifiers to change the palette.")]
public readonly bool AllowModifiers = true;

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
public class ClassicParallelProductionQueue : ProductionQueue
{
static readonly ActorInfo[] NoItems = { };
static readonly ActorInfo[] NoItems = Array.Empty<ActorInfo>();
readonly Actor self;
readonly ClassicParallelProductionQueueInfo info;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
@@ -35,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
public class ClassicProductionQueue : ProductionQueue
{
static readonly ActorInfo[] NoItems = { };
static readonly ActorInfo[] NoItems = Array.Empty<ActorInfo>();
readonly Actor self;
readonly ClassicProductionQueueInfo info;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -21,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Prerequisite = null;
[Desc("Only grant this prerequisite when you have these prerequisites.")]
public readonly string[] RequiresPrerequisites = { };
public readonly string[] RequiresPrerequisites = Array.Empty<string>();
[Desc("Only grant this prerequisite for certain factions.")]
public readonly HashSet<string> Factions = new HashSet<string>();

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
@@ -24,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Name;
[Desc("Prerequisites to grant when this tech level is active.")]
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
IEnumerable<string> ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info) { return Prerequisites; }
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
readonly ProvidesTechPrerequisiteInfo info;
bool enabled;
static readonly string[] NoPrerequisites = new string[0];
static readonly string[] NoPrerequisites = Array.Empty<string>();
public string Name => info.Name;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -18,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
"trait, the production queue icon renders with an overlay defined in that trait.")]
public class ProducibleWithLevelInfo : TraitInfo, Requires<GainsExperienceInfo>
{
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
[Desc("Number of levels to give to the actor on creation.")]
public readonly int InitialLevels = 1;

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
{
[FieldLoader.Require]
[Desc("e.g. Infantry, Vehicles, Aircraft, Buildings")]
public readonly string[] Produces = { };
public readonly string[] Produces = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new Production(init, this); }
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -39,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly string Palette = "chrome";
[Desc("Name(s) of AmmoPool(s) that use this decoration. Leave empty to include all pools.")]
public readonly string[] AmmoPools = { };
public readonly string[] AmmoPools = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new WithAmmoPipsDecoration(init.Self, this); }
}

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits.Render
class WithCrateBodyInfo : TraitInfo, Requires<RenderSpritesInfo>, IRenderActorPreviewSpritesInfo
{
[Desc("Easteregg sequences to use in December.")]
public readonly string[] XmasImages = { };
public readonly string[] XmasImages = Array.Empty<string>();
[Desc("Terrain types on which to display WaterSequence.")]
public readonly HashSet<string> WaterTerrainTypes = new HashSet<string> { "Water" };

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -20,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits.Render
class WithDeadBridgeSpriteBodyInfo : WithSpriteBodyInfo
{
[ActorReference]
public readonly string[] RampActors = { };
public readonly string[] RampActors = Array.Empty<string>();
[Desc("Offset to search for the 'A' neighbour")]
public readonly CVec AOffset = CVec.Zero;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -41,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly int BlinkInterval = 5;
[Desc("A pattern of ticks (BlinkInterval long) where the decoration is visible or hidden.")]
public readonly BlinkState[] BlinkPattern = { };
public readonly BlinkState[] BlinkPattern = Array.Empty<BlinkState>();
[Desc("Override blink conditions to use when defined conditions are enabled.",
"A dictionary of [condition string]: [pattern].")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -20,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits.Render
class WithGateSpriteBodyInfo : WithSpriteBodyInfo, IWallConnectorInfo, Requires<GateInfo>
{
[Desc("Cells (outside the gate footprint) that contain wall cells that can connect to the gate")]
public readonly CVec[] WallConnections = { };
public readonly CVec[] WallConnections = Array.Empty<CVec>();
[Desc("Wall type for connections")]
public readonly string Type = "wall";

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -35,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly Dictionary<string, string[]> AttackSequences = new Dictionary<string, string[]>();
[SequenceReference]
public readonly string[] IdleSequences = { };
public readonly string[] IdleSequences = Array.Empty<string>();
[SequenceReference]
public readonly string[] StandSequences = { "stand" };

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int RefundPercent = 50;
[Desc("List of audio clips to play when the actor is being sold.")]
public readonly string[] SellSounds = { };
public readonly string[] SellSounds = Array.Empty<string>();
[NotificationReference("Speech")]
[Desc("The audio notification type to play.")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Traits;
@@ -18,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
public class AttackSoundsInfo : ConditionalTraitInfo
{
[Desc("Play a randomly selected sound from this list when preparing for an attack or attacking.")]
public readonly string[] Sounds = { };
public readonly string[] Sounds = Array.Empty<string>();
[Desc("Delay in ticks before sound starts, either relative to attack preparation or attack.")]
public readonly int Delay = 0;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -17,10 +18,10 @@ namespace OpenRA.Mods.Common.Traits.Sound
public class SoundOnDamageTransitionInfo : TraitInfo
{
[Desc("Play a random sound from this list when damaged.")]
public readonly string[] DamagedSounds = { };
public readonly string[] DamagedSounds = Array.Empty<string>();
[Desc("Play a random sound from this list when destroyed.")]
public readonly string[] DestroyedSounds = { };
public readonly string[] DestroyedSounds = Array.Empty<string>();
[Desc("DamageType(s) that trigger the sounds. Leave empty to always trigger a sound.")]
public readonly BitSet<DamageType> DamageTypes = default(BitSet<DamageType>);

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
@@ -61,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits
[SequenceReference(nameof(TrailImage), allowNullImage: true)]
[Desc("Loop a randomly chosen sequence of TrailImage from this list while this projectile is moving.")]
public readonly string[] TrailSequences = { };
public readonly string[] TrailSequences = Array.Empty<string>();
[Desc("Interval in ticks between each spawned Trail animation.")]
public readonly int TrailInterval = 1;

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
[ActorReference(typeof(PassengerInfo))]
[Desc("Troops to be delivered. They will be distributed between the planes if SquadSize > 1.")]
public readonly string[] DropItems = { };
public readonly string[] DropItems = Array.Empty<string>();
[Desc("Risks stuck units when they don't have the Paratrooper trait.")]
public readonly bool AllowImpassableCells = false;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
@@ -45,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("If set to true, the support power will be fully charged when it becomes available. " +
"Normal rules apply for subsequent charges.")]
public readonly bool StartFullyCharged = false;
public readonly string[] Prerequisites = { };
public readonly string[] Prerequisites = Array.Empty<string>();
public readonly string DetectedSound = null;

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits
Powers[order.OrderString].Activate(order);
}
static readonly SupportPowerInstance[] NoInstances = { };
static readonly SupportPowerInstance[] NoInstances = Array.Empty<SupportPowerInstance>();
public IEnumerable<SupportPowerInstance> GetPowersForActor(Actor a)
{

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
@@ -21,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
[WeaponReference]
[FieldLoader.Require]
[Desc("The weapons used for shrapnel.")]
public readonly string[] Weapons = { };
public readonly string[] Weapons = Array.Empty<string>();
[Desc("The amount of pieces of shrapnel to expel. Two values indicate a range.")]
public readonly int[] Pieces = { 3, 10 };

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
@@ -32,10 +33,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly WAngle Facing = new WAngle(384);
[Desc("Sounds to play when transforming.")]
public readonly string[] TransformSounds = { };
public readonly string[] TransformSounds = Array.Empty<string>();
[Desc("Sounds to play when the transformation is blocked.")]
public readonly string[] NoTransformSounds = { };
public readonly string[] NoTransformSounds = Array.Empty<string>();
[NotificationReference("Speech")]
[Desc("Notification to play when transforming.")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
@@ -32,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[ActorReference]
[Desc("Name of the actor that will be randomly picked to spawn.")]
public readonly string[] Actors = { };
public readonly string[] Actors = Array.Empty<string>();
public readonly string Owner = "Creeps";

View File

@@ -32,10 +32,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly float SimilarityThreshold = 0.314f;
[Desc("List of hue components for the preset colors in the palette tab. Each entry must have a corresponding PresetSaturations definition.")]
public readonly float[] PresetHues = { };
public readonly float[] PresetHues = Array.Empty<float>();
[Desc("List of saturation components for the preset colors in the palette tab. Each entry must have a corresponding PresetHues definition.")]
public readonly float[] PresetSaturations = { };
public readonly float[] PresetSaturations = Array.Empty<float>();
[ActorReference]
[Desc("Actor type to show in the color picker. This can be overridden for specific factions with FactionPreviewActors.")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("A group of units ready to defend or scout.")]
[ActorReference]
public readonly string[] SupportActors = { };
public readonly string[] SupportActors = Array.Empty<string>();
[Desc("Inner radius for spawning support actors")]
public readonly int InnerSupportRadius = 2;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[SequenceReference(nameof(Image))]
[Desc("Randomly chosen image sequences.")]
public readonly string[] Sequences = { };
public readonly string[] Sequences = Array.Empty<string>();
[PaletteReference]
[Desc("Palette used for rendering the resource sprites.")]

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -42,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
[SequenceReference(nameof(SmokeImage))]
[Desc("Smoke sprite sequences randomly chosen from")]
public readonly string[] SmokeSequences = { };
public readonly string[] SmokeSequences = Array.Empty<string>();
[PaletteReference]
public readonly string SmokePalette = "effect";

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Effects;
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Warheads
{
[SequenceReference(nameof(Image), allowNullImage: true)]
[Desc("List of explosion sequences that can be used.")]
public readonly string[] Explosions = new string[0];
public readonly string[] Explosions = Array.Empty<string>();
[Desc("Image containing explosion effect sequence.")]
public readonly string Image = "explosion";
@@ -38,7 +39,7 @@ namespace OpenRA.Mods.Common.Warheads
public readonly bool ForceDisplayAtGroundLevel = false;
[Desc("List of sounds that can be played on impact.")]
public readonly string[] ImpactSounds = new string[0];
public readonly string[] ImpactSounds = Array.Empty<string>();
[Desc("Chance of impact sound to play.")]
public readonly int ImpactSoundChance = 100;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Widgets
readonly World world;
int selectionHash;
Actor[] selectedActors = { };
Actor[] selectedActors = Array.Empty<Actor>();
bool attackMoveDisabled = true;
bool forceMoveDisabled = true;
bool forceAttackDisabled = true;

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
template = scrollPanel.Get<ContainerWidget>("PACKAGE_TEMPLATE");
var headerTemplate = panel.Get<LabelWidget>("HEADER_TEMPLATE");
var headerLines = !string.IsNullOrEmpty(content.HeaderMessage) ? content.HeaderMessage.Replace("\\n", "\n").Split('\n') : new string[0];
var headerLines = !string.IsNullOrEmpty(content.HeaderMessage) ? content.HeaderMessage.Replace("\\n", "\n").Split('\n') : Array.Empty<string>();
var headerHeight = 0;
foreach (var l in headerLines)
{

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var panel = widget.Get("CONTENT_PROMPT_PANEL");
var headerTemplate = panel.Get<LabelWidget>("HEADER_TEMPLATE");
var headerLines = !string.IsNullOrEmpty(content.InstallPromptMessage) ? content.InstallPromptMessage.Replace("\\n", "\n").Split('\n') : new string[0];
var headerLines = !string.IsNullOrEmpty(content.InstallPromptMessage) ? content.InstallPromptMessage.Replace("\\n", "\n").Split('\n') : Array.Empty<string>();
var headerHeight = 0;
foreach (var l in headerLines)
{

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Widgets
count = FieldLoader.GetValue<int>("HotkeyCount", countNode.Value.Value);
if (count == 0)
return new string[0];
return Array.Empty<string>();
if (string.IsNullOrEmpty(prefix))
emitError($"{widgetNode.Location} must define HotkeyPrefix if HotkeyCount > 0.");

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets
count = FieldLoader.GetValue<int>("HotkeyCount", countNode.Value.Value);
if (count == 0)
return new string[0];
return Array.Empty<string>();
if (string.IsNullOrEmpty(prefix))
emitError($"{widgetNode.Location} must define HotkeyPrefix if HotkeyCount > 0.");

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -27,7 +28,7 @@ namespace OpenRA.Mods.D2k.Traits
public readonly HashSet<string> UnsafeTerrainTypes = new HashSet<string> { "Rock" };
[Desc("Only check for 'unsafe' footprint tiles when you have these prerequisites.")]
public readonly string[] RequiresPrerequisites = { };
public readonly string[] RequiresPrerequisites = Array.Empty<string>();
[Desc("Sprite image to use for the overlay.")]
public readonly string Image = "overlay";

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.IO;
using System.Linq;
using OpenRA.Mods.Common.Terrain;
@@ -43,7 +44,7 @@ namespace OpenRA.Mods.D2k.Traits.Buildings
public readonly ushort ConcreteTemplate = 88;
[Desc("List of required prerequisites to place a terrain template.")]
public readonly string[] ConcretePrerequisites = { };
public readonly string[] ConcretePrerequisites = Array.Empty<string>();
public override object Create(ActorInitializer init) { return new D2kBuilding(init, this); }
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Server
// Special case handling of Game.Mod argument: if it matches a real filesystem path
// then we use this to override the mod search path, and replace it with the mod id
var modID = arguments.GetValue("Game.Mod", null);
var explicitModPaths = new string[0];
var explicitModPaths = Array.Empty<string>();
if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
{
explicitModPaths = new[] { modID };

View File

@@ -73,7 +73,7 @@ namespace OpenRA
}
var modId = args[0];
var explicitModPaths = new string[0];
var explicitModPaths = Array.Empty<string>();
if (File.Exists(modId) || Directory.Exists(modId))
{
explicitModPaths = new[] { modId };