Enforce use of 'var' instead of explicit type.

This commit is contained in:
Matthias Mailänder
2022-12-26 15:28:53 +01:00
committed by Matthias Mailänder
parent 982c97dc6c
commit 19ecddcd86
16 changed files with 31 additions and 28 deletions

View File

@@ -126,6 +126,9 @@ dotnet_style_predefined_type_for_locals_parameters_members = true
# Show an IDE warning when default access modifiers are explicitly specified. # Show an IDE warning when default access modifiers are explicitly specified.
dotnet_style_require_accessibility_modifiers = omit_if_default:warning dotnet_style_require_accessibility_modifiers = omit_if_default:warning
# use 'var' instead of explicit type
dotnet_diagnostic.IDE0007.severity = warning
# Don't prefer braces (for one liners). # Don't prefer braces (for one liners).
dotnet_diagnostic.IDE0011.severity = silent dotnet_diagnostic.IDE0011.severity = silent

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Graphics
public ImmutablePalette(IPalette p) public ImmutablePalette(IPalette p)
{ {
for (int i = 0; i < Palette.Size; i++) for (var i = 0; i < Palette.Size; i++)
colors[i] = p[i]; colors[i] = p[i];
} }

View File

@@ -344,7 +344,7 @@ namespace OpenRA
if (yaml.TryGetValue("Visibility", out temp)) if (yaml.TryGetValue("Visibility", out temp))
newData.Visibility = FieldLoader.GetValue<MapVisibility>("Visibility", temp.Value); newData.Visibility = FieldLoader.GetValue<MapVisibility>("Visibility", temp.Value);
string requiresMod = string.Empty; var requiresMod = string.Empty;
if (yaml.TryGetValue("RequiresMod", out temp)) if (yaml.TryGetValue("RequiresMod", out temp))
requiresMod = temp.Value; requiresMod = temp.Value;

View File

@@ -131,7 +131,7 @@ namespace OpenRA.Network
Log.Write("sync", $"\t {a.ActorID} {a.Type} {a.Owner} {a.Trait} ({a.Hash})"); Log.Write("sync", $"\t {a.ActorID} {a.Type} {a.Owner} {a.Trait} ({a.Hash})");
var nvp = a.NamesValues; var nvp = a.NamesValues;
for (int i = 0; i < nvp.Names.Length; i++) for (var i = 0; i < nvp.Names.Length; i++)
if (nvp.Values[i] != null) if (nvp.Values[i] != null)
Log.Write("sync", $"\t\t {nvp.Names[i]}: {nvp.Values[i]}"); Log.Write("sync", $"\t\t {nvp.Names[i]}: {nvp.Values[i]}");
} }
@@ -142,7 +142,7 @@ namespace OpenRA.Network
Log.Write("sync", "\t {0} ({1})", e.Name, e.Hash); Log.Write("sync", "\t {0} ({1})", e.Name, e.Hash);
var nvp = e.NamesValues; var nvp = e.NamesValues;
for (int i = 0; i < nvp.Names.Length; i++) for (var i = 0; i < nvp.Names.Length; i++)
if (nvp.Values[i] != null) if (nvp.Values[i] != null)
Log.Write("sync", $"\t\t {nvp.Names[i]}: {nvp.Values[i]}"); Log.Write("sync", $"\t\t {nvp.Names[i]}: {nvp.Values[i]}");
} }

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Scripting
public static bool TryGetClrValue<T>(this LuaValue value, out T clrObject) public static bool TryGetClrValue<T>(this LuaValue value, out T clrObject)
{ {
var ret = value.TryGetClrValue(typeof(T), out object temp); var ret = value.TryGetClrValue(typeof(T), out var temp);
clrObject = ret ? (T)temp : default; clrObject = ret ? (T)temp : default;
return ret; return ret;
} }

View File

@@ -77,12 +77,12 @@ namespace OpenRA.Mods.Cnc.FileFormats
byte* ip; byte* ip;
uint t; uint t;
byte* mPos; byte* mPos;
byte* ipEnd = @in + inLen; var ipEnd = @in + inLen;
outLen = 0; outLen = 0;
op = @out; op = @out;
ip = @in; ip = @in;
bool gtFirstLiteralRun = false; var gtFirstLiteralRun = false;
bool gtMatchDone = false; var gtMatchDone = false;
if (*ip > 17) if (*ip > 17)
{ {
t = (uint)(*ip++ - 17); t = (uint)(*ip++ - 17);

View File

@@ -338,8 +338,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var mapSection = file.GetSection("IsoMapPack5"); var mapSection = file.GetSection("IsoMapPack5");
var data = Convert.FromBase64String(string.Concat(mapSection.Select(kvp => kvp.Value))); var data = Convert.FromBase64String(string.Concat(mapSection.Select(kvp => kvp.Value)));
int cells = (fullSize.X * 2 - 1) * fullSize.Y; var cells = (fullSize.X * 2 - 1) * fullSize.Y;
int lzoPackSize = cells * 11 + 4; // last 4 bytes contains a lzo pack header saying no more data is left var lzoPackSize = cells * 11 + 4; // last 4 bytes contains a lzo pack header saying no more data is left
var isoMapPack = new byte[lzoPackSize]; var isoMapPack = new byte[lzoPackSize];
UnpackLZO(data, isoMapPack); UnpackLZO(data, isoMapPack);
@@ -354,8 +354,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var z = mf.ReadUInt8(); var z = mf.ReadUInt8();
/*var zero2 = */mf.ReadUInt8(); /*var zero2 = */mf.ReadUInt8();
int dx = rx - ry + fullSize.X - 1; var dx = rx - ry + fullSize.X - 1;
int dy = rx + ry - fullSize.X - 1; var dy = rx + ry - fullSize.X - 1;
var mapCell = new MPos(dx / 2, dy); var mapCell = new MPos(dx / 2, dy);
var cell = mapCell.ToCPos(map); var cell = mapCell.ToCPos(map);

View File

@@ -760,10 +760,10 @@ namespace OpenRA.Mods.Common.Projectiles
WVec HomingTick(World world, in WVec tarDistVec, int relTarHorDist) WVec HomingTick(World world, in WVec tarDistVec, int relTarHorDist)
{ {
int predClfHgt = 0; var predClfHgt = 0;
int predClfDist = 0; var predClfDist = 0;
int lastHtChg = 0; var lastHtChg = 0;
int lastHt = 0; var lastHt = 0;
if (info.TerrainHeightAware) if (info.TerrainHeightAware)
InclineLookahead(world, relTarHorDist, out predClfHgt, out predClfDist, out lastHtChg, out lastHt); InclineLookahead(world, relTarHorDist, out predClfHgt, out predClfDist, out lastHtChg, out lastHt);

View File

@@ -175,8 +175,8 @@ namespace OpenRA.Mods.Common.Scripting
return false; return false;
} }
AsyncLoader l = new AsyncLoader(Media.LoadVideo); var l = new AsyncLoader(Media.LoadVideo);
IAsyncResult ar = l.BeginInvoke(s, null, null); var ar = l.BeginInvoke(s, null, null);
Action onLoadComplete = () => Action onLoadComplete = () =>
{ {
Media.StopFMVInRadar(); Media.StopFMVInRadar();

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common
/// /// </summary> /// /// </summary>
public static Target RecalculateInvalidatingHiddenTargets(this Target t, Player viewer) public static Target RecalculateInvalidatingHiddenTargets(this Target t, Player viewer)
{ {
var updated = t.Recalculate(viewer, out bool targetIsHiddenActor); var updated = t.Recalculate(viewer, out var targetIsHiddenActor);
return targetIsHiddenActor ? Target.Invalid : updated; return targetIsHiddenActor ? Target.Invalid : updated;
} }

View File

@@ -342,7 +342,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var chosenTarget = Target.Invalid; var chosenTarget = Target.Invalid;
var chosenTargetPriority = int.MinValue; var chosenTargetPriority = int.MinValue;
int chosenTargetRange = 0; var chosenTargetRange = 0;
var activePriorities = activeTargetPriorities.ToList(); var activePriorities = activeTargetPriorities.ToList();
if (activePriorities.Count == 0) if (activePriorities.Count == 0)

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits
var type = BuildingType.Building; var type = BuildingType.Building;
CPos? location = null; CPos? location = null;
var actorVariant = 0; var actorVariant = 0;
string orderString = "PlaceBuilding"; var orderString = "PlaceBuilding";
// Check if Building is a plug for other Building // Check if Building is a plug for other Building
var actorInfo = world.Map.Rules.Actors[currentBuilding.Item]; var actorInfo = world.Map.Rules.Actors[currentBuilding.Item];

View File

@@ -376,7 +376,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var availCells = new List<CPos>(); var availCells = new List<CPos>();
var notStupidCells = new List<CPos>(); var notStupidCells = new List<CPos>();
foreach (CVec direction in CVec.Directions) foreach (var direction in CVec.Directions)
{ {
var p = ToCell + direction; var p = ToCell + direction;
if (CanEnterCell(p) && CanStayInCell(p) && (preferToAvoid == null || !preferToAvoid(p))) if (CanEnterCell(p) && CanStayInCell(p) && (preferToAvoid == null || !preferToAvoid(p)))

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{ {
var knownKeys = new HashSet<TKey>(); var knownKeys = new HashSet<TKey>();
foreach (TSource element in source) foreach (var element in source)
{ {
if (knownKeys.Add(keySelector(element))) if (knownKeys.Add(keySelector(element)))
yield return element; yield return element;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
return PrintUsage(); return PrintUsage();
var invalid = false; var invalid = false;
for (int i = 1; i < args.Length; i++) for (var i = 1; i < args.Length; i++)
{ {
var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 3 && parts.Length != 4) if (parts.Length != 3 && parts.Length != 4)
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
[Desc("Convert r,g,b[,a] triples/quads into hex colors")] [Desc("Convert r,g,b[,a] triples/quads into hex colors")]
void IUtilityCommand.Run(Utility utility, string[] args) void IUtilityCommand.Run(Utility utility, string[] args)
{ {
for (int i = 1; i < args.Length;) for (var i = 1; i < args.Length;)
{ {
var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 3) if (parts.Length == 3)
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
return PrintUsage(); return PrintUsage();
var invalid = false; var invalid = false;
for (int i = 1; i < args.Length; i++) for (var i = 1; i < args.Length; i++)
{ {
var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 3 && parts.Length != 4) if (parts.Length != 3 && parts.Length != 4)
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
[Desc("Convert a,r,g,b legacy colors into hex colors")] [Desc("Convert a,r,g,b legacy colors into hex colors")]
void IUtilityCommand.Run(Utility utility, string[] args) void IUtilityCommand.Run(Utility utility, string[] args)
{ {
for (int i = 1; i < args.Length;) for (var i = 1; i < args.Length;)
{ {
var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 3) if (parts.Length == 3)

View File

@@ -188,7 +188,7 @@ namespace OpenRA.Mods.Common.Widgets
var animations = new ModelAnimation[] { animation }; var animations = new ModelAnimation[] { animation };
ModelPreview preview = new ModelPreview( var preview = new ModelPreview(
new ModelAnimation[] { animation }, WVec.Zero, 0, new ModelAnimation[] { animation }, WVec.Zero, 0,
cachedScale, cachedScale,
new WAngle(cachedLightPitch), new WAngle(cachedLightPitch),