diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 4a1113df53..9b41efe7b8 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -159,7 +159,7 @@ namespace OpenRA if (xs.Count == 0) { if (throws) - throw new ArgumentException("Collection must not be empty.", "ts"); + throw new ArgumentException("Collection must not be empty.", nameof(ts)); else return default(T); } @@ -236,7 +236,7 @@ namespace OpenRA { if (!e.MoveNext()) if (throws) - throw new ArgumentException("Collection must not be empty.", "ts"); + throw new ArgumentException("Collection must not be empty.", nameof(ts)); else return default(T); t = e.Current; diff --git a/OpenRA.Game/FileFormats/ReplayMetadata.cs b/OpenRA.Game/FileFormats/ReplayMetadata.cs index 464b2766dd..9d4d37f2aa 100644 --- a/OpenRA.Game/FileFormats/ReplayMetadata.cs +++ b/OpenRA.Game/FileFormats/ReplayMetadata.cs @@ -28,7 +28,7 @@ namespace OpenRA.FileFormats public ReplayMetadata(GameInformation info) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); GameInfo = info; } diff --git a/OpenRA.Game/GameInformation.cs b/OpenRA.Game/GameInformation.cs index ef10fcbcd6..96acd686e1 100644 --- a/OpenRA.Game/GameInformation.cs +++ b/OpenRA.Game/GameInformation.cs @@ -97,10 +97,10 @@ namespace OpenRA public void AddPlayer(OpenRA.Player runtimePlayer, Session lobbyInfo) { if (runtimePlayer == null) - throw new ArgumentNullException("runtimePlayer"); + throw new ArgumentNullException(nameof(runtimePlayer)); if (lobbyInfo == null) - throw new ArgumentNullException("lobbyInfo"); + throw new ArgumentNullException(nameof(lobbyInfo)); // We don't care about spectators and map players if (runtimePlayer.NonCombatant || !runtimePlayer.Playable) diff --git a/OpenRA.Game/Graphics/SpriteFont.cs b/OpenRA.Game/Graphics/SpriteFont.cs index 21d8bc3fe1..e1dbdbf4ba 100644 --- a/OpenRA.Game/Graphics/SpriteFont.cs +++ b/OpenRA.Game/Graphics/SpriteFont.cs @@ -32,7 +32,7 @@ namespace OpenRA.Graphics public SpriteFont(string name, byte[] data, int size, int ascender, float scale, SheetBuilder builder) { if (builder.Type != SheetType.BGRA) - throw new ArgumentException("The sheet builder must create BGRA sheets.", "builder"); + throw new ArgumentException("The sheet builder must create BGRA sheets.", nameof(builder)); deviceScale = scale; this.size = size; diff --git a/OpenRA.Game/Map/CellLayerBase.cs b/OpenRA.Game/Map/CellLayerBase.cs index 6cb5411a28..42e29aabd4 100644 --- a/OpenRA.Game/Map/CellLayerBase.cs +++ b/OpenRA.Game/Map/CellLayerBase.cs @@ -38,7 +38,7 @@ namespace OpenRA public virtual void CopyValuesFrom(CellLayerBase anotherLayer) { if (Size != anotherLayer.Size || GridType != anotherLayer.GridType) - throw new ArgumentException("Layers must have a matching size and shape (grid type).", "anotherLayer"); + throw new ArgumentException("Layers must have a matching size and shape (grid type).", nameof(anotherLayer)); Array.Copy(anotherLayer.entries, entries, entries.Length); } diff --git a/OpenRA.Game/Map/CellRegion.cs b/OpenRA.Game/Map/CellRegion.cs index e4707149dd..a3a23e6f51 100644 --- a/OpenRA.Game/Map/CellRegion.cs +++ b/OpenRA.Game/Map/CellRegion.cs @@ -62,7 +62,7 @@ namespace OpenRA public static CellRegion BoundingRegion(MapGridType shape, IEnumerable cells) { if (cells == null || !cells.Any()) - throw new ArgumentException("cells must not be null or empty.", "cells"); + throw new ArgumentException("cells must not be null or empty.", nameof(cells)); var minU = int.MaxValue; var minV = int.MaxValue; diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index c757ebf841..bbc7fe954f 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -1246,10 +1246,10 @@ namespace OpenRA public IEnumerable FindTilesInAnnulus(CPos center, int minRange, int maxRange, bool allowOutsideBounds = false) { if (maxRange < minRange) - throw new ArgumentOutOfRangeException("maxRange", "Maximum range is less than the minimum range."); + throw new ArgumentOutOfRangeException(nameof(maxRange), "Maximum range is less than the minimum range."); if (maxRange >= Grid.TilesByDistance.Length) - throw new ArgumentOutOfRangeException("maxRange", + throw new ArgumentOutOfRangeException(nameof(maxRange), "The requested range ({0}) cannot exceed the value of MaximumTileSearchRange ({1})".F(maxRange, Grid.MaximumTileSearchRange)); for (var i = minRange; i <= maxRange; i++) diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index 134e8843fa..dbf6810801 100644 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -296,7 +296,7 @@ namespace OpenRA.Network case 1: return item2OrSentinel; case 2: return item3; case 3: return item4; - default: throw new ArgumentOutOfRangeException("index"); + default: throw new ArgumentOutOfRangeException(nameof(index)); } } @@ -314,7 +314,7 @@ namespace OpenRA.Network case 1: item2OrSentinel = value; break; case 2: item3 = value; break; case 3: item4 = value; break; - default: throw new ArgumentOutOfRangeException("index"); + default: throw new ArgumentOutOfRangeException(nameof(index)); } } } diff --git a/OpenRA.Game/Primitives/ActionQueue.cs b/OpenRA.Game/Primitives/ActionQueue.cs index 0177280565..09bdcff491 100644 --- a/OpenRA.Game/Primitives/ActionQueue.cs +++ b/OpenRA.Game/Primitives/ActionQueue.cs @@ -24,7 +24,7 @@ namespace OpenRA.Primitives public void Add(Action a, long desiredTime) { if (a == null) - throw new ArgumentNullException("a"); + throw new ArgumentNullException(nameof(a)); lock (actions) { diff --git a/OpenRA.Game/Primitives/Cache.cs b/OpenRA.Game/Primitives/Cache.cs index ff9a5b75f2..359e773537 100644 --- a/OpenRA.Game/Primitives/Cache.cs +++ b/OpenRA.Game/Primitives/Cache.cs @@ -22,7 +22,7 @@ namespace OpenRA.Primitives public Cache(Func loader, IEqualityComparer c) { if (loader == null) - throw new ArgumentNullException("loader"); + throw new ArgumentNullException(nameof(loader)); this.loader = loader; cache = new Dictionary(c); diff --git a/OpenRA.Game/Primitives/ConcurrentCache.cs b/OpenRA.Game/Primitives/ConcurrentCache.cs index cefbd7a2fd..c380829fce 100644 --- a/OpenRA.Game/Primitives/ConcurrentCache.cs +++ b/OpenRA.Game/Primitives/ConcurrentCache.cs @@ -23,7 +23,7 @@ namespace OpenRA.Primitives public ConcurrentCache(Func loader, IEqualityComparer c) { if (loader == null) - throw new ArgumentNullException("loader"); + throw new ArgumentNullException(nameof(loader)); this.loader = loader; cache = new ConcurrentDictionary(c); diff --git a/OpenRA.Game/Primitives/ReadOnlyAdapterStream.cs b/OpenRA.Game/Primitives/ReadOnlyAdapterStream.cs index 1001332b0c..e18b035d02 100644 --- a/OpenRA.Game/Primitives/ReadOnlyAdapterStream.cs +++ b/OpenRA.Game/Primitives/ReadOnlyAdapterStream.cs @@ -28,9 +28,9 @@ namespace OpenRA.Primitives protected ReadOnlyAdapterStream(Stream stream) { if (stream == null) - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); if (!stream.CanRead) - throw new ArgumentException("stream must be readable.", "stream"); + throw new ArgumentException("stream must be readable.", nameof(stream)); baseStream = stream; } diff --git a/OpenRA.Game/Primitives/ReadOnlyDictionary.cs b/OpenRA.Game/Primitives/ReadOnlyDictionary.cs index 692c7b68fc..d301ca840c 100644 --- a/OpenRA.Game/Primitives/ReadOnlyDictionary.cs +++ b/OpenRA.Game/Primitives/ReadOnlyDictionary.cs @@ -57,7 +57,7 @@ namespace OpenRA public ReadOnlyDictionary(IDictionary dict) { if (dict == null) - throw new ArgumentNullException("dict"); + throw new ArgumentNullException(nameof(dict)); this.dict = dict; } diff --git a/OpenRA.Game/Primitives/ReadOnlyList.cs b/OpenRA.Game/Primitives/ReadOnlyList.cs index 40070efb1a..d505c594ed 100644 --- a/OpenRA.Game/Primitives/ReadOnlyList.cs +++ b/OpenRA.Game/Primitives/ReadOnlyList.cs @@ -52,7 +52,7 @@ namespace OpenRA public ReadOnlyList(IList list) { if (list == null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); this.list = list; } diff --git a/OpenRA.Game/Primitives/SegmentStream.cs b/OpenRA.Game/Primitives/SegmentStream.cs index 7b24bdba7b..e34c732460 100644 --- a/OpenRA.Game/Primitives/SegmentStream.cs +++ b/OpenRA.Game/Primitives/SegmentStream.cs @@ -33,13 +33,13 @@ namespace OpenRA.Primitives public SegmentStream(Stream stream, long offset, long count) { if (stream == null) - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); if (!stream.CanSeek) - throw new ArgumentException("stream must be seekable.", "stream"); + throw new ArgumentException("stream must be seekable.", nameof(stream)); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", "offset must be non-negative."); + throw new ArgumentOutOfRangeException(nameof(offset), "offset must be non-negative."); if (count < 0) - throw new ArgumentOutOfRangeException("count", "count must be non-negative."); + throw new ArgumentOutOfRangeException(nameof(count), "count must be non-negative."); BaseStream = stream; BaseOffset = offset; @@ -93,7 +93,7 @@ namespace OpenRA.Primitives { switch (origin) { - default: throw new InvalidEnumArgumentException("origin", (int)origin, typeof(SeekOrigin)); + default: throw new InvalidEnumArgumentException(nameof(origin), (int)origin, typeof(SeekOrigin)); case SeekOrigin.Begin: return BaseStream.Seek(BaseOffset + offset, SeekOrigin.Begin) - offset; case SeekOrigin.Current: diff --git a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs index 9732da0eff..410be1e068 100644 --- a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs +++ b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs @@ -33,7 +33,7 @@ namespace OpenRA.Primitives void ValidateBounds(T actor, Rectangle bounds) { if (bounds.Width == 0 || bounds.Height == 0) - throw new ArgumentException("Bounds of actor {0} are empty.".F(actor), "bounds"); + throw new ArgumentException("Bounds of actor {0} are empty.".F(actor), nameof(bounds)); } public void Add(T item, Rectangle bounds) diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 5a0e48a097..7a4e2aba89 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -349,7 +349,7 @@ namespace OpenRA bool relative, WPos pos, float volumeModifier, bool attenuateVolume) { if (ruleset == null) - throw new ArgumentNullException("ruleset"); + throw new ArgumentNullException(nameof(ruleset)); if (definition == null || DisableAllSounds || (DisableWorldSounds && soundType == SoundType.World)) return false; @@ -416,7 +416,7 @@ namespace OpenRA public bool PlayNotification(Ruleset rules, Player player, string type, string notification, string variant) { if (rules == null) - throw new ArgumentNullException("rules"); + throw new ArgumentNullException(nameof(rules)); if (type == null || notification == null) return false; diff --git a/OpenRA.Game/StreamExts.cs b/OpenRA.Game/StreamExts.cs index ce67dc33e2..ea43497ab0 100644 --- a/OpenRA.Game/StreamExts.cs +++ b/OpenRA.Game/StreamExts.cs @@ -22,7 +22,7 @@ namespace OpenRA public static byte[] ReadBytes(this Stream s, int count) { if (count < 0) - throw new ArgumentOutOfRangeException("count", "Non-negative number required."); + throw new ArgumentOutOfRangeException(nameof(count), "Non-negative number required."); var buffer = new byte[count]; s.ReadBytes(buffer, 0, count); return buffer; @@ -31,7 +31,7 @@ namespace OpenRA public static void ReadBytes(this Stream s, byte[] buffer, int offset, int count) { if (count < 0) - throw new ArgumentOutOfRangeException("count", "Non-negative number required."); + throw new ArgumentOutOfRangeException(nameof(count), "Non-negative number required."); while (count > 0) { int bytesRead; diff --git a/OpenRA.Game/Support/Log.cs b/OpenRA.Game/Support/Log.cs index c1399302d0..df21610a85 100644 --- a/OpenRA.Game/Support/Log.cs +++ b/OpenRA.Game/Support/Log.cs @@ -40,7 +40,7 @@ namespace OpenRA ChannelInfo info; lock (Channels) if (!Channels.TryGetValue(channelName, out info)) - throw new ArgumentException("Tried logging to non-existent channel " + channelName, "channelName"); + throw new ArgumentException("Tried logging to non-existent channel " + channelName, nameof(channelName)); return info; } diff --git a/OpenRA.Game/Support/MersenneTwister.cs b/OpenRA.Game/Support/MersenneTwister.cs index e674333f24..189306e7b6 100644 --- a/OpenRA.Game/Support/MersenneTwister.cs +++ b/OpenRA.Game/Support/MersenneTwister.cs @@ -51,7 +51,7 @@ namespace OpenRA.Support public int Next(int low, int high) { if (high < low) - throw new ArgumentOutOfRangeException("high", "Maximum value is less than the minimum value."); + throw new ArgumentOutOfRangeException(nameof(high), "Maximum value is less than the minimum value."); var diff = high - low; if (diff <= 1) diff --git a/OpenRA.Game/Traits/Player/Shroud.cs b/OpenRA.Game/Traits/Player/Shroud.cs index aa4e44cf5e..8946514811 100644 --- a/OpenRA.Game/Traits/Player/Shroud.cs +++ b/OpenRA.Game/Traits/Player/Shroud.cs @@ -321,7 +321,7 @@ namespace OpenRA.Traits public void Explore(Shroud s) { if (map.Bounds != s.map.Bounds) - throw new ArgumentException("The map bounds of these shrouds do not match.", "s"); + throw new ArgumentException("The map bounds of these shrouds do not match.", nameof(s)); foreach (var puv in map.ProjectedCells) { diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index e16e25b861..2001bf0df2 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -124,7 +124,7 @@ namespace OpenRA return; if (!Players.Contains(localPlayer)) - throw new ArgumentException("The local player must be one of the players in the world.", "localPlayer"); + throw new ArgumentException("The local player must be one of the players in the world.", nameof(localPlayer)); if (IsReplay) return; diff --git a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs index dfdb890560..884e8771e6 100644 --- a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs +++ b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs @@ -158,10 +158,10 @@ namespace OpenRA.Mods.Cnc.FileSystem static uint[] ReadBlocks(Stream s, long offset, int count) { if (offset < 0) - throw new ArgumentOutOfRangeException("offset", "Non-negative number required."); + throw new ArgumentOutOfRangeException(nameof(offset), "Non-negative number required."); if (count < 0) - throw new ArgumentOutOfRangeException("count", "Non-negative number required."); + throw new ArgumentOutOfRangeException(nameof(count), "Non-negative number required."); if (offset + (count * 2) > s.Length) throw new ArgumentException("Bytes to read {0} and offset {1} greater than stream length {2}.".F(count * 2, offset, s.Length)); diff --git a/OpenRA.Mods.Cnc/Graphics/Voxel.cs b/OpenRA.Mods.Cnc/Graphics/Voxel.cs index 6c45f4c0f1..f90d1f3bc2 100644 --- a/OpenRA.Mods.Cnc/Graphics/Voxel.cs +++ b/OpenRA.Mods.Cnc/Graphics/Voxel.cs @@ -60,9 +60,9 @@ namespace OpenRA.Mods.Cnc.Graphics public float[] TransformationMatrix(uint limb, uint frame) { if (frame >= frames) - throw new ArgumentOutOfRangeException("frame", "Only {0} frames exist.".F(frames)); + throw new ArgumentOutOfRangeException(nameof(frame), "Only {0} frames exist.".F(frames)); if (limb >= limbs) - throw new ArgumentOutOfRangeException("limb", "Only {1} limbs exist.".F(limbs)); + throw new ArgumentOutOfRangeException(nameof(limb), "Only {1} limbs exist.".F(limbs)); var l = limbData[limb]; var t = new float[16]; diff --git a/OpenRA.Mods.Common/DiscordService.cs b/OpenRA.Mods.Common/DiscordService.cs index e5756f047e..c404ecdb73 100644 --- a/OpenRA.Mods.Common/DiscordService.cs +++ b/OpenRA.Mods.Common/DiscordService.cs @@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common timestamp = DateTime.UtcNow; break; default: - throw new ArgumentOutOfRangeException("state", state, null); + throw new ArgumentOutOfRangeException(nameof(state), state, null); } var richPresence = new RichPresence diff --git a/OpenRA.Mods.Common/Traits/GainsExperience.cs b/OpenRA.Mods.Common/Traits/GainsExperience.cs index 18e1dbd5c9..966bfac323 100644 --- a/OpenRA.Mods.Common/Traits/GainsExperience.cs +++ b/OpenRA.Mods.Common/Traits/GainsExperience.cs @@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits public void GiveExperience(int amount, bool silent = false) { if (amount < 0) - throw new ArgumentException("Revoking experience is not implemented.", "amount"); + throw new ArgumentException("Revoking experience is not implemented.", nameof(amount)); if (MaxLevel == 0) return; diff --git a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs index 84ae25f33b..6370a2ddb0 100644 --- a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs @@ -113,16 +113,16 @@ namespace OpenRA.Mods.Common.Traits public ShroudRenderer(World world, ShroudRendererInfo info) { if (info.ShroudVariants.Length != info.FogVariants.Length) - throw new ArgumentException("ShroudRenderer must define the same number of shroud and fog variants!", "info"); + throw new ArgumentException("ShroudRenderer must define the same number of shroud and fog variants!", nameof(info)); if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null)) - throw new ArgumentException("ShroudRenderer cannot define overrides for only one of shroud or fog!", "info"); + throw new ArgumentException("ShroudRenderer cannot define overrides for only one of shroud or fog!", nameof(info)); if (info.ShroudVariants.Length > byte.MaxValue) - throw new ArgumentException("ShroudRenderer cannot define this many shroud and fog variants.", "info"); + throw new ArgumentException("ShroudRenderer cannot define this many shroud and fog variants.", nameof(info)); if (info.Index.Length >= byte.MaxValue) - throw new ArgumentException("ShroudRenderer cannot define this many indexes for shroud directions.", "info"); + throw new ArgumentException("ShroudRenderer cannot define this many indexes for shroud directions.", nameof(info)); this.info = info; this.world = world; diff --git a/OpenRA.Mods.Common/Util.cs b/OpenRA.Mods.Common/Util.cs index 327fd4aabe..a70109c57a 100644 --- a/OpenRA.Mods.Common/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -279,7 +279,7 @@ namespace OpenRA.Mods.Common case InaccuracyType.Absolute: return inaccuracy; default: - throw new InvalidEnumArgumentException("inaccuracyType", (int)inaccuracyType, typeof(InaccuracyType)); + throw new InvalidEnumArgumentException(nameof(inaccuracyType), (int)inaccuracyType, typeof(InaccuracyType)); } } } diff --git a/OpenRA.Mods.Common/UtilityCommands/Utilities.cs b/OpenRA.Mods.Common/UtilityCommands/Utilities.cs index c8f2cc3ed1..4ce26a0be2 100644 --- a/OpenRA.Mods.Common/UtilityCommands/Utilities.cs +++ b/OpenRA.Mods.Common/UtilityCommands/Utilities.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.UtilityCommands string mapPath = null) { if (manifestPropertySelector == null) - throw new ArgumentNullException("manifestPropertySelector", "Must pass a non-null manifestPropertySelector"); + throw new ArgumentNullException(nameof(manifestPropertySelector), "Must pass a non-null manifestPropertySelector"); Map map = null; if (mapPath != null) diff --git a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs index 66af4f6ab8..c6f1b5fdb3 100644 --- a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs +++ b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs @@ -276,7 +276,7 @@ namespace OpenRA.Mods.D2k.UtilityCommands stream = File.OpenRead(filename); if (stream.Length == 0 || stream.Length % 4 != 0) - throw new ArgumentException("The map is in an unrecognized format!", "filename"); + throw new ArgumentException("The map is in an unrecognized format!", nameof(filename)); Initialize(filename); FillMap();