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

@@ -272,10 +272,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Select the first visible
var firstVisible = assetVisByName.FirstOrDefault(kvp => kvp.Value);
IReadOnlyPackage package;
string filename;
if (firstVisible.Key != null && modData.DefaultFileSystem.TryGetPackageContaining(firstVisible.Key, out package, out filename))
if (firstVisible.Key != null && modData.DefaultFileSystem.TryGetPackageContaining(firstVisible.Key, out var package, out var filename))
LoadAsset(package, filename);
}
@@ -290,8 +288,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
item.IsVisible = () =>
{
bool visible;
if (assetVisByName.TryGetValue(filepath, out visible))
if (assetVisByName.TryGetValue(filepath, out var visible))
return visible;
visible = FilterAsset(filepath);

View File

@@ -27,8 +27,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public ColorPickerLogic(Widget widget, ModData modData, World world, Color initialColor, string initialFaction, Action<Color> onChange,
Dictionary<string, MiniYaml> logicArgs)
{
string actorType;
if (initialFaction == null || !ChromeMetrics.TryGet("ColorPickerActorType-" + initialFaction, out actorType))
if (initialFaction == null || !ChromeMetrics.TryGet("ColorPickerActorType-" + initialFaction, out string actorType))
actorType = ChromeMetrics.Get<string>("ColorPickerActorType");
var preview = widget.GetOrNull<ActorPreviewWidget>("PREVIEW");
@@ -103,8 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var palettePresetRows = 2;
var paletteCustomRows = 1;
MiniYaml yaml;
if (logicArgs.TryGetValue("PaletteColumns", out yaml))
if (logicArgs.TryGetValue("PaletteColumns", out var yaml))
if (!int.TryParse(yaml.Value, out paletteCols))
throw new YamlException("Invalid value for PaletteColumns: {0}".F(yaml.Value));
if (logicArgs.TryGetValue("PalettePresetRows", out yaml))
@@ -189,9 +187,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
static float HueFromColor(Color c)
{
float h, s, v;
int a;
c.ToAhsv(out a, out h, out s, out v);
c.ToAhsv(out var a, out var h, out var s, out var v);
return h;
}

View File

@@ -106,8 +106,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
actorIDErrorLabel.GetText = () => actorIDStatus == ActorIDStatus.Duplicate ?
"Duplicate Actor ID" : "Enter an Actor ID";
MiniYaml yaml;
if (logicArgs.TryGetValue("EditPanelPadding", out yaml))
if (logicArgs.TryGetValue("EditPanelPadding", out var yaml))
editPanelPadding = FieldLoader.GetValue<int>("EditPanelPadding", yaml.Value);
okButton.IsDisabled = () => !IsValid() || !editActorPreview.IsDirty;

View File

@@ -45,9 +45,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = () =>
{
int width, height;
int.TryParse(widthTextField.Text, out width);
int.TryParse(heightTextField.Text, out height);
int.TryParse(widthTextField.Text, out var width);
int.TryParse(heightTextField.Text, out var height);
// Require at least a 2x2 playable area so that the
// ground is visible through the edge shroud

View File

@@ -19,8 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public AddFactionSuffixLogic(Widget widget, World world)
{
string faction;
if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out faction))
if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out string faction))
faction = world.LocalPlayer.Faction.InternalName;
var suffix = "-" + faction;

View File

@@ -36,8 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
selection = world.Selection;
this.world = world;
MiniYaml yaml;
if (logicArgs.TryGetValue("ClickSound", out yaml))
if (logicArgs.TryGetValue("ClickSound", out var yaml))
clickSound = yaml.Value;
}

View File

@@ -209,8 +209,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
}
MiniYaml yaml;
if (logicArgs.TryGetValue("ChatLineSound", out yaml))
if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
chatLineSound = yaml.Value;
}

View File

@@ -74,20 +74,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
buttonContainer.RemoveChild(buttonTemplate);
buttonContainer.IsVisible = () => !hideMenu;
MiniYaml buttonStrideNode;
if (logicArgs.TryGetValue("ButtonStride", out buttonStrideNode))
if (logicArgs.TryGetValue("ButtonStride", out var buttonStrideNode))
buttonStride = FieldLoader.GetValue<int2>("ButtonStride", buttonStrideNode.Value);
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
MiniYaml buttonsNode;
if (logicArgs.TryGetValue("Buttons", out buttonsNode))
if (logicArgs.TryGetValue("Buttons", out var buttonsNode))
{
Action createHandler;
var buttonIds = FieldLoader.GetValue<string[]>("Buttons", buttonsNode.Value);
foreach (var button in buttonIds)
if (buttonHandlers.TryGetValue(button, out createHandler))
if (buttonHandlers.TryGetValue(button, out var createHandler))
createHandler();
}

View File

@@ -35,8 +35,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
worldRoot = Ui.Root.Get("WORLD_ROOT");
menuRoot = Ui.Root.Get("MENU_ROOT");
MiniYaml yaml;
// System buttons
var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
if (options != null)
@@ -85,7 +83,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
}
if (logicArgs.TryGetValue("ClickSound", out yaml))
if (logicArgs.TryGetValue("ClickSound", out var yaml))
clickSound = yaml.Value;
}

View File

@@ -76,8 +76,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
this.world = world;
MiniYaml yaml;
if (logicArgs.TryGetValue("CombinedViewKey", out yaml))
if (logicArgs.TryGetValue("CombinedViewKey", out var yaml))
combinedViewKey = modData.Hotkeys[yaml.Value];
if (logicArgs.TryGetValue("WorldViewKey", out yaml))

View File

@@ -165,8 +165,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
static string ActorName(Ruleset rules, string a)
{
ActorInfo ai;
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai))
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out var ai))
{
var actorTooltip = ai.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
if (actorTooltip != null)

View File

@@ -450,8 +450,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (skirmishMode)
addBotOnMapLoad = true;
MiniYaml yaml;
if (logicArgs.TryGetValue("ChatLineSound", out yaml))
if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
chatLineSound = yaml.Value;
}

View File

@@ -138,8 +138,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var getOptionLabel = new CachedTransform<string, string>(id =>
{
string value;
if (id == null || !option.Values.TryGetValue(id, out value))
if (id == null || !option.Values.TryGetValue(id, out var value))
return "Not Available";
return value;

View File

@@ -215,8 +215,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void EnumerateMaps(MapClassification tab, ScrollItemWidget template)
{
int playerCountFilter;
if (!int.TryParse(mapFilter, out playerCountFilter))
if (!int.TryParse(mapFilter, out var playerCountFilter))
playerCountFilter = -1;
var maps = tabMaps[tab]

View File

@@ -26,9 +26,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
musicPlaylist = world.WorldActor.Trait<MusicPlaylist>();
MiniYaml yaml;
var stopKey = new HotkeyReference();
if (logicArgs.TryGetValue("StopMusicKey", out yaml))
if (logicArgs.TryGetValue("StopMusicKey", out var yaml))
stopKey = modData.Hotkeys[yaml.Value];
var pauseKey = new HotkeyReference();

View File

@@ -177,8 +177,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void CreateAndJoin()
{
var name = Settings.SanitizedServerName(panel.Get<TextFieldWidget>("SERVER_NAME").Text);
int listenPort;
if (!Exts.TryParseIntegerInvariant(panel.Get<TextFieldWidget>("LISTEN_PORT").Text, out listenPort))
if (!Exts.TryParseIntegerInvariant(panel.Get<TextFieldWidget>("LISTEN_PORT").Text, out var listenPort))
listenPort = 1234;
var passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");

View File

@@ -370,9 +370,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return () =>
{
int x, y;
Exts.TryParseIntegerInvariant(windowWidth.Text, out x);
Exts.TryParseIntegerInvariant(windowHeight.Text, out y);
Exts.TryParseIntegerInvariant(windowWidth.Text, out var x);
Exts.TryParseIntegerInvariant(windowHeight.Text, out var y);
ds.WindowedSize = new int2(x, y);
nameTextfield.YieldKeyboardFocus();
};
@@ -590,8 +589,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Func<bool> returnTrue = () => true;
Action doNothing = () => { };
MiniYaml hotkeyGroups;
if (logicArgs.TryGetValue("HotkeyGroups", out hotkeyGroups))
if (logicArgs.TryGetValue("HotkeyGroups", out var hotkeyGroups))
{
InitHotkeyRemapDialog(panel);

View File

@@ -18,10 +18,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
protected SingleHotkeyBaseLogic(Widget widget, ModData modData, string argName, string parentName, Dictionary<string, MiniYaml> logicArgs)
{
MiniYaml yaml;
var namedKey = new HotkeyReference();
if (logicArgs.TryGetValue(argName, out yaml))
if (logicArgs.TryGetValue(argName, out var yaml))
namedKey = modData.Hotkeys[yaml.Value];
var keyhandler = widget.Get<LogicKeyListenerWidget>(parentName);