Use out var syntax

This commit is contained in:
teinarss
2020-08-16 10:49:33 +02:00
committed by Paul Chote
parent d52e4793fe
commit 27f1a7ab27
193 changed files with 395 additions and 826 deletions

View File

@@ -47,14 +47,9 @@ namespace OpenRA.Primitives
BitSetIndex bits = 0;
lock (Bits)
{
foreach (var value in values)
{
BitSetIndex valueBit;
if (Bits.TryGetValue(value, out valueBit))
if (Bits.TryGetValue(value, out var valueBit))
bits |= valueBit;
}
}
return bits;
}

View File

@@ -124,10 +124,10 @@ namespace OpenRA.Primitives
if (value.Length != 6 && value.Length != 8)
return false;
byte red, green, blue, alpha = 255;
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out red)
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out green)
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out blue))
byte alpha = 255;
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var red)
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var green)
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var blue))
return false;
if (value.Length == 8

View File

@@ -50,14 +50,9 @@ namespace OpenRA.Primitives
long bits = 0;
lock (Bits)
{
foreach (var value in values)
{
long valueBit;
if (Bits.TryGetValue(value, out valueBit))
if (Bits.TryGetValue(value, out var valueBit))
bits |= valueBit;
}
}
return bits;
}

View File

@@ -120,8 +120,7 @@ namespace OpenRA.Primitives
/// <param name="count">The length of the segment.</param>
public static Stream CreateWithoutOwningStream(Stream stream, long offset, int count)
{
Stream parentStream;
var nestedOffset = offset + GetOverallNestedOffset(stream, out parentStream);
var nestedOffset = offset + GetOverallNestedOffset(stream, out var parentStream);
// Special case FileStream - instead of creating an in-memory copy,
// just reference the portion of the on-disk file that we need to save memory.

View File

@@ -52,8 +52,7 @@ namespace OpenRA.Primitives
public bool Remove(T item)
{
Rectangle bounds;
if (!itemBounds.TryGetValue(item, out bounds))
if (!itemBounds.TryGetValue(item, out var bounds))
return false;
MutateBins(item, bounds, removeItem);
@@ -91,8 +90,7 @@ namespace OpenRA.Primitives
void MutateBins(T actor, Rectangle bounds, Action<Dictionary<T, Rectangle>, T, Rectangle> action)
{
int minRow, maxRow, minCol, maxCol;
BoundsToBinRowsAndCols(bounds, out minRow, out maxRow, out minCol, out maxCol);
BoundsToBinRowsAndCols(bounds, out var minRow, out var maxRow, out var minCol, out var maxCol);
for (var row = minRow; row < maxRow; row++)
for (var col = minCol; col < maxCol; col++)
@@ -110,8 +108,7 @@ namespace OpenRA.Primitives
public IEnumerable<T> InBox(Rectangle box)
{
int minRow, maxRow, minCol, maxCol;
BoundsToBinRowsAndCols(box, out minRow, out maxRow, out minCol, out maxCol);
BoundsToBinRowsAndCols(box, out var minRow, out var maxRow, out var minCol, out var maxCol);
// We want to return any items intersecting the box.
// If the box covers multiple bins, we must handle items that are contained in multiple bins and avoid

View File

@@ -61,8 +61,7 @@ namespace OpenRA.Primitives
object Get(Type t, bool throwsIfMissing)
{
List<object> ret;
if (!data.TryGetValue(t, out ret))
if (!data.TryGetValue(t, out var ret))
{
if (throwsIfMissing)
throw new InvalidOperationException("TypeDictionary does not contain instance of type `{0}`".F(t));
@@ -76,8 +75,7 @@ namespace OpenRA.Primitives
public IEnumerable<T> WithInterface<T>()
{
List<object> objs;
if (data.TryGetValue(typeof(T), out objs))
if (data.TryGetValue(typeof(T), out var objs))
return objs.Cast<T>();
return new T[0];
}
@@ -94,8 +92,7 @@ namespace OpenRA.Primitives
void InnerRemove(Type t, object val)
{
List<object> objs;
if (!data.TryGetValue(t, out objs))
if (!data.TryGetValue(t, out var objs))
return;
objs.Remove(val);
if (objs.Count == 0)