Change throw exceptions to use nameof in parameter
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA
|
||||
public virtual void CopyValuesFrom(CellLayerBase<T> 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);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA
|
||||
public static CellRegion BoundingRegion(MapGridType shape, IEnumerable<CPos> 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;
|
||||
|
||||
@@ -1246,10 +1246,10 @@ namespace OpenRA
|
||||
public IEnumerable<CPos> 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++)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Primitives
|
||||
public Cache(Func<T, U> loader, IEqualityComparer<T> c)
|
||||
{
|
||||
if (loader == null)
|
||||
throw new ArgumentNullException("loader");
|
||||
throw new ArgumentNullException(nameof(loader));
|
||||
|
||||
this.loader = loader;
|
||||
cache = new Dictionary<T, U>(c);
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Primitives
|
||||
public ConcurrentCache(Func<T, U> loader, IEqualityComparer<T> c)
|
||||
{
|
||||
if (loader == null)
|
||||
throw new ArgumentNullException("loader");
|
||||
throw new ArgumentNullException(nameof(loader));
|
||||
|
||||
this.loader = loader;
|
||||
cache = new ConcurrentDictionary<T, U>(c);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA
|
||||
public ReadOnlyDictionary(IDictionary<TKey, TValue> dict)
|
||||
{
|
||||
if (dict == null)
|
||||
throw new ArgumentNullException("dict");
|
||||
throw new ArgumentNullException(nameof(dict));
|
||||
|
||||
this.dict = dict;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA
|
||||
public ReadOnlyList(IList<T> list)
|
||||
{
|
||||
if (list == null)
|
||||
throw new ArgumentNullException("list");
|
||||
throw new ArgumentNullException(nameof(list));
|
||||
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user