Fix IDE0038

This commit is contained in:
RoosterDragon
2023-02-19 11:28:54 +00:00
committed by Gustas
parent 71ce515d6d
commit 5b70d344cc
15 changed files with 33 additions and 29 deletions

View File

@@ -153,7 +153,7 @@ dotnet_diagnostic.IDE0018.severity = warning
# Use pattern matching to avoid 'as' followed by a 'null' check. # Use pattern matching to avoid 'as' followed by a 'null' check.
dotnet_diagnostic.IDE0019.severity = warning dotnet_diagnostic.IDE0019.severity = warning
# Use pattern matching to avoid 'is' check followed by a cast. # Use pattern matching to avoid 'is' check followed by a cast (with variable).
dotnet_diagnostic.IDE0020.severity = warning dotnet_diagnostic.IDE0020.severity = warning
# Collection initialization can be simplified. # Collection initialization can be simplified.
@@ -177,6 +177,9 @@ dotnet_diagnostic.IDE0034.severity = warning
# Modifiers are not ordered. # Modifiers are not ordered.
dotnet_diagnostic.IDE0036.severity = warning dotnet_diagnostic.IDE0036.severity = warning
# Use pattern matching to avoid 'is' check followed by a cast (without variable).
dotnet_diagnostic.IDE0038.severity = warning
# Use local function instead of lambda. # Use local function instead of lambda.
dotnet_diagnostic.IDE0039.severity = warning dotnet_diagnostic.IDE0039.severity = warning

View File

@@ -56,7 +56,7 @@ namespace OpenRA
public override int GetHashCode() { return Bits.GetHashCode(); } public override int GetHashCode() { return Bits.GetHashCode(); }
public bool Equals(CPos other) { return Bits == other.Bits; } public bool Equals(CPos other) { return Bits == other.Bits; }
public override bool Equals(object obj) { return obj is CPos && Equals((CPos)obj); } public override bool Equals(object obj) { return obj is CPos cell && Equals(cell); }
public override string ToString() public override string ToString()
{ {

View File

@@ -55,7 +55,7 @@ namespace OpenRA
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public bool Equals(CVec other) { return other == this; } public bool Equals(CVec other) { return other == this; }
public override bool Equals(object obj) { return obj is CVec && Equals((CVec)obj); } public override bool Equals(object obj) { return obj is CVec vec && Equals(vec); }
public override string ToString() { return X + "," + Y; } public override string ToString() { return X + "," + Y; }

View File

@@ -27,7 +27,7 @@ namespace OpenRA
public override int GetHashCode() { return U.GetHashCode() ^ V.GetHashCode(); } public override int GetHashCode() { return U.GetHashCode() ^ V.GetHashCode(); }
public bool Equals(MPos other) { return other == this; } public bool Equals(MPos other) { return other == this; }
public override bool Equals(object obj) { return obj is MPos && Equals((MPos)obj); } public override bool Equals(object obj) { return obj is MPos uv && Equals(uv); }
public MPos Clamp(Rectangle r) public MPos Clamp(Rectangle r)
{ {
@@ -88,7 +88,7 @@ namespace OpenRA
public override int GetHashCode() { return U.GetHashCode() ^ V.GetHashCode(); } public override int GetHashCode() { return U.GetHashCode() ^ V.GetHashCode(); }
public bool Equals(PPos other) { return other == this; } public bool Equals(PPos other) { return other == this; }
public override bool Equals(object obj) { return obj is PPos && Equals((PPos)obj); } public override bool Equals(object obj) { return obj is PPos puv && Equals(puv); }
public override string ToString() { return U + "," + V; } public override string ToString() { return U + "," + V; }
} }

View File

@@ -58,7 +58,7 @@ namespace OpenRA
public override int GetHashCode() { return M11 ^ M22 ^ M33 ^ M44; } public override int GetHashCode() { return M11 ^ M22 ^ M33 ^ M44; }
public bool Equals(Int32Matrix4x4 other) { return other == this; } public bool Equals(Int32Matrix4x4 other) { return other == this; }
public override bool Equals(object obj) { return obj is Int32Matrix4x4 && Equals((Int32Matrix4x4)obj); } public override bool Equals(object obj) { return obj is Int32Matrix4x4 matrix && Equals(matrix); }
public override string ToString() public override string ToString()
{ {

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Primitives
public static bool operator !=(LongBitSet<T> me, LongBitSet<T> other) { return !(me == other); } public static bool operator !=(LongBitSet<T> me, LongBitSet<T> other) { return !(me == other); }
public bool Equals(LongBitSet<T> other) { return other == this; } public bool Equals(LongBitSet<T> other) { return other == this; }
public override bool Equals(object obj) { return obj is LongBitSet<T> && Equals((LongBitSet<T>)obj); } public override bool Equals(object obj) { return obj is LongBitSet<T> set && Equals(set); }
public override int GetHashCode() { return bits.GetHashCode(); } public override int GetHashCode() { return bits.GetHashCode(); }
public bool IsEmpty => bits == 0; public bool IsEmpty => bits == 0;

View File

@@ -72,7 +72,7 @@ namespace OpenRA
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public bool Equals(float2 other) { return this == other; } public bool Equals(float2 other) { return this == other; }
public override bool Equals(object obj) { return obj is float2 && Equals((float2)obj); } public override bool Equals(object obj) { return obj is float2 vec && Equals(vec); }
public override string ToString() { return X + "," + Y; } public override string ToString() { return X + "," + Y; }

View File

@@ -37,7 +37,7 @@ namespace OpenRA
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public bool Equals(int2 other) { return this == other; } public bool Equals(int2 other) { return this == other; }
public override bool Equals(object obj) { return obj is int2 && Equals((int2)obj); } public override bool Equals(object obj) { return obj is int2 vec && Equals(vec); }
public override string ToString() { return X + "," + Y; } public override string ToString() { return X + "," + Y; }

View File

@@ -109,10 +109,9 @@ namespace OpenRA.Scripting
} }
// Translate LuaTable<int, object> -> object[] // Translate LuaTable<int, object> -> object[]
if (value is LuaTable && t.IsArray) if (value is LuaTable table && t.IsArray)
{ {
var innerType = t.GetElementType(); var innerType = t.GetElementType();
var table = (LuaTable)value;
var array = Array.CreateInstance(innerType, table.Count); var array = Array.CreateInstance(innerType, table.Count);
var i = 0; var i = 0;
@@ -149,23 +148,25 @@ namespace OpenRA.Scripting
public static LuaValue ToLuaValue(this object obj, ScriptContext context) public static LuaValue ToLuaValue(this object obj, ScriptContext context)
{ {
if (obj is LuaValue) {
return (LuaValue)obj; if (obj is LuaValue v)
return v;
if (obj == null) if (obj == null)
return LuaNil.Instance; return LuaNil.Instance;
if (obj is double) if (obj is double d)
return (double)obj; return d;
if (obj is int) if (obj is int i)
return (int)obj; return i;
if (obj is bool) if (obj is bool b)
return (bool)obj; return b;
if (obj is string) if (obj is string s)
return (string)obj; return s;
}
if (obj is IScriptBindable) if (obj is IScriptBindable)
{ {

View File

@@ -44,7 +44,7 @@ namespace OpenRA
public override int GetHashCode() { return Angle.GetHashCode(); } public override int GetHashCode() { return Angle.GetHashCode(); }
public bool Equals(WAngle other) { return other == this; } public bool Equals(WAngle other) { return other == this; }
public override bool Equals(object obj) { return obj is WAngle && Equals((WAngle)obj); } public override bool Equals(object obj) { return obj is WAngle angle && Equals(angle); }
public int Facing => Angle / 4; public int Facing => Angle / 4;

View File

@@ -93,7 +93,7 @@ namespace OpenRA
public override int GetHashCode() { return Length.GetHashCode(); } public override int GetHashCode() { return Length.GetHashCode(); }
public bool Equals(WDist other) { return other == this; } public bool Equals(WDist other) { return other == this; }
public override bool Equals(object obj) { return obj is WDist && Equals((WDist)obj); } public override bool Equals(object obj) { return obj is WDist dist && Equals(dist); }
public int CompareTo(object obj) public int CompareTo(object obj)
{ {

View File

@@ -190,7 +190,7 @@ namespace OpenRA
public override int GetHashCode() { return Roll.GetHashCode() ^ Pitch.GetHashCode() ^ Yaw.GetHashCode(); } public override int GetHashCode() { return Roll.GetHashCode() ^ Pitch.GetHashCode() ^ Yaw.GetHashCode(); }
public bool Equals(WRot other) { return other == this; } public bool Equals(WRot other) { return other == this; }
public override bool Equals(object obj) { return obj is WRot && Equals((WRot)obj); } public override bool Equals(object obj) { return obj is WRot rot && Equals(rot); }
public override string ToString() { return Roll + "," + Pitch + "," + Yaw; } public override string ToString() { return Roll + "," + Pitch + "," + Yaw; }

View File

@@ -102,7 +102,7 @@ namespace OpenRA
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
public bool Equals(WVec other) { return other == this; } public bool Equals(WVec other) { return other == this; }
public override bool Equals(object obj) { return obj is WVec && Equals((WVec)obj); } public override bool Equals(object obj) { return obj is WVec vec && Equals(vec); }
public override string ToString() { return X + "," + Y + "," + Z; } public override string ToString() { return X + "," + Y + "," + Z; }

View File

@@ -637,7 +637,7 @@ namespace OpenRA
public override int GetHashCode() { return Actor.GetHashCode() ^ Trait.GetHashCode(); } public override int GetHashCode() { return Actor.GetHashCode() ^ Trait.GetHashCode(); }
public bool Equals(TraitPair<T> other) { return this == other; } public bool Equals(TraitPair<T> other) { return this == other; }
public override bool Equals(object obj) { return obj is TraitPair<T> && Equals((TraitPair<T>)obj); } public override bool Equals(object obj) { return obj is TraitPair<T> pair && Equals(pair); }
public override string ToString() { return Actor.Info.Name + "->" + Trait.GetType().Name; } public override string ToString() { return Actor.Info.Name + "->" + Trait.GetType().Name; }
} }

View File

@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Common.Traits
if (palette == null) if (palette == null)
return r; return r;
else else
return r.Select(a => !a.IsDecoration && a is IPalettedRenderable ? ((IPalettedRenderable)a).WithPalette(palette) : a); return r.Select(a => !a.IsDecoration && a is IPalettedRenderable pr ? pr.WithPalette(palette) : a);
} }
else else
return SpriteRenderable.None; return SpriteRenderable.None;