Change to use pattern matching

This commit is contained in:
teinarss
2021-02-28 19:00:32 +01:00
committed by reaperrr
parent 7c0e4b25ae
commit d60c05eff3
35 changed files with 63 additions and 122 deletions

View File

@@ -371,9 +371,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
currentPackage = package;
currentFilename = filename;
var prefix = "";
var fs = modData.DefaultFileSystem as OpenRA.FileSystem.FileSystem;
if (fs != null)
if (modData.DefaultFileSystem is OpenRA.FileSystem.FileSystem fs)
{
prefix = fs.GetPrefix(package);
if (prefix != null)

View File

@@ -180,8 +180,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
try
{
var package = map.Package as IReadWritePackage;
if (package == null || package.Name != combinedPath)
if (!(map.Package is IReadWritePackage package) || package.Name != combinedPath)
{
selectedDirectory.Folder.Delete(combinedPath);
if (fileType == MapFileType.OraMap)

View File

@@ -273,12 +273,10 @@ namespace OpenRA.Mods.Common.Widgets
bool IsForceModifiersActive(Modifiers modifiers)
{
var fmog = world.OrderGenerator as ForceModifiersOrderGenerator;
if (fmog != null && fmog.Modifiers.HasFlag(modifiers))
if (world.OrderGenerator is ForceModifiersOrderGenerator fmog && fmog.Modifiers.HasFlag(modifiers))
return true;
var uog = world.OrderGenerator as UnitOrderGenerator;
if (uog != null && Game.GetModifierKeys().HasFlag(modifiers))
if (world.OrderGenerator is UnitOrderGenerator uog && Game.GetModifierKeys().HasFlag(modifiers))
return true;
return false;

View File

@@ -65,8 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
status.GetText = statusText;
}
var timerTooltip = timer as LabelWithTooltipWidget;
if (timerTooltip != null)
if (timer is LabelWithTooltipWidget timerTooltip)
{
var connection = orderManager.Connection as ReplayConnection;
if (connection != null && connection.FinalGameTick != 0)

View File

@@ -19,8 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public SellOrderButtonLogic(Widget widget, World world)
{
var sell = widget as ButtonWidget;
if (sell != null)
if (widget is ButtonWidget sell)
OrderButtonsChromeUtils.BindOrderButton<SellOrderGenerator>(world, sell, "sell");
}
}
@@ -30,8 +29,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public RepairOrderButtonLogic(Widget widget, World world)
{
var repair = widget as ButtonWidget;
if (repair != null)
if (widget is ButtonWidget repair)
OrderButtonsChromeUtils.BindOrderButton<RepairOrderGenerator>(world, repair, "repair");
}
}
@@ -41,8 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public PowerdownOrderButtonLogic(Widget widget, World world)
{
var power = widget as ButtonWidget;
if (power != null)
if (widget is ButtonWidget power)
OrderButtonsChromeUtils.BindOrderButton<PowerDownOrderGenerator>(world, power, "power");
}
}
@@ -52,8 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public BeaconOrderButtonLogic(Widget widget, World world)
{
var beacon = widget as ButtonWidget;
if (beacon != null)
if (widget is ButtonWidget beacon)
OrderButtonsChromeUtils.BindOrderButton<BeaconOrderGenerator>(world, beacon, "beacon");
}
}

View File

@@ -282,8 +282,7 @@ namespace OpenRA.Mods.Common.Widgets
{
var item = Children.FirstOrDefault(c =>
{
var si = c as ScrollItemWidget;
return si != null && si.ItemKey == itemKey;
return c is ScrollItemWidget si && si.ItemKey == itemKey;
});
if (item != null)
@@ -294,8 +293,7 @@ namespace OpenRA.Mods.Common.Widgets
{
var item = Children.FirstOrDefault(c =>
{
var si = c as ScrollItemWidget;
return si != null && si.IsSelected();
return c is ScrollItemWidget si && si.IsSelected();
});
if (item != null)

View File

@@ -88,9 +88,8 @@ namespace OpenRA.Mods.Common.Widgets
var useClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle;
var multiClick = mi.MultiTapCount >= 2;
var uog = World.OrderGenerator as UnitOrderGenerator;
if (uog == null)
if (!(World.OrderGenerator is UnitOrderGenerator uog))
{
ApplyOrders(World, mi);
isDragging = false;