Enable Net 7 and Net 8 style rules.

This commit is contained in:
RoosterDragon
2024-11-25 20:15:58 +00:00
committed by Gustas Kažukauskas
parent 71ae0aedfb
commit cfde11556f
31 changed files with 74 additions and 94 deletions

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Widgets
}
}
class PaintMarkerTileEditorAction : IEditorAction
sealed class PaintMarkerTileEditorAction : IEditorAction
{
[FluentReference("amount", "type")]
const string AddedMarkerTiles = "notification-added-marker-tiles";
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Widgets
}
}
class ClearSelectedMarkerTilesEditorAction : IEditorAction
sealed class ClearSelectedMarkerTilesEditorAction : IEditorAction
{
[FluentReference("amount", "type")]
const string ClearedSelectedMarkerTiles = "notification-cleared-selected-marker-tiles";
@@ -195,7 +195,7 @@ namespace OpenRA.Mods.Common.Widgets
}
}
class ClearAllMarkerTilesEditorAction : IEditorAction
sealed class ClearAllMarkerTilesEditorAction : IEditorAction
{
[FluentReference("amount")]
const string ClearedAllMarkerTiles = "notification-cleared-all-marker-tiles";
@@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Widgets
this.markerLayerOverlay = markerLayerOverlay;
tiles = new Dictionary<int, HashSet<CPos>>(markerLayerOverlay.Tiles);
var allTilesCount = tiles.Values.Select(x => x.Count).Sum();
var allTilesCount = tiles.Values.Sum(x => x.Count);
Text = FluentProvider.GetMessage(ClearedAllMarkerTiles, "amount", allTilesCount);
}

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.FileFormats
var audioFormat = s.ReadInt16();
audioType = (WaveType)audioFormat;
if (!Enum.IsDefined(typeof(WaveType), audioType))
if (!Enum.IsDefined(audioType))
throw new NotSupportedException($"Compression type {audioFormat} is not supported.");
channels = s.ReadInt16();

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.FileSystem
[RequireExplicitImplementation]
public interface IFileSystemExternalContent
{
public bool InstallContentIfRequired(ModData modData);
bool InstallContentIfRequired(ModData modData);
}
public class DefaultFileSystemLoader : IFileSystemLoader

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common
{
public class ItchIntegration : IGlobalModData
{
class User
sealed class User
{
[JsonProperty("url")]
public string Url { get; set; }
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common
public string DisplayName { get; set; }
}
class Root
sealed class Root
{
public User User { get; set; }
}

View File

@@ -502,7 +502,7 @@ namespace OpenRA.Mods.Common.Lint
}
}
class Keys
sealed class Keys
{
readonly HashSet<string> keys = new();
readonly List<(string Key, string Context)> keysWithContext = new();

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Lint
{
// Remove the "Info" suffix.
var traitName = traitInfo.GetType().Name;
traitName = traitName.Remove(traitName.Length - 4);
traitName = traitName[..^4];
var fields = Utility.GetFields(traitInfo.GetType());
foreach (var field in fields)

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Lint
{
// Remove the "Info" suffix.
var traitName = traitInfo.GetType().Name;
traitName = traitName.Remove(traitName.Length - 4);
traitName = traitName[..^4];
var locations = traitLocation.SystemActors.ToString().Replace(", ", " or ");
emitError($"`{traitName}` does not belong on `{actorInfo.Key}`. It is a system trait meant for {locations}.");
}

View File

@@ -567,7 +567,7 @@ namespace OpenRA.Mods.Common.Scripting
"so you must not add new triggers at the same time that you are calling this function.")]
public void Clear(Actor actor, string triggerName)
{
var trigger = (Trigger)Enum.Parse(typeof(Trigger), triggerName);
var trigger = Enum.Parse<Trigger>(triggerName);
if (actor == null)
throw new NullReferenceException(nameof(actor));

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Scripting
public event Action<Actor, Actor> OnProducedInternal = (a, b) => { };
public event Action<Actor, Actor> OnOtherProducedInternal = (a, b) => { };
readonly List<Triggerable>[] triggerables = Exts.MakeArray(Enum.GetValues(typeof(Trigger)).Length, _ => new List<Triggerable>());
readonly List<Triggerable>[] triggerables = Exts.MakeArray(Enum.GetValues<Trigger>().Length, _ => new List<Triggerable>());
readonly struct Triggerable : IDisposable
{
@@ -526,7 +526,7 @@ namespace OpenRA.Mods.Common.Scripting
public void ClearAll()
{
foreach (Trigger t in Enum.GetValues(typeof(Trigger)))
foreach (var t in Enum.GetValues<Trigger>())
Clear(t);
}

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Server
{
public class SkirmishLogic : ServerTrait, IClientJoined, INotifySyncLobbyInfo
{
class SkirmishSlot
sealed class SkirmishSlot
{
[FieldLoader.Serialize(FromYamlKey = true)]
public readonly string Slot;

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var visOptionTemplate = visibilityPanel.Get<CheckboxWidget>("VISIBILITY_TEMPLATE");
visibilityPanel.RemoveChildren();
foreach (MapVisibility visibilityOption in Enum.GetValues(typeof(MapVisibility)))
foreach (var visibilityOption in Enum.GetValues<MapVisibility>())
{
// To prevent users from breaking the game only show the 'Shellmap' option when it is already set.
if (visibilityOption == MapVisibility.Shellmap && !map.Visibility.HasFlag(visibilityOption))
@@ -311,8 +311,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
try
{
if (package == null)
throw new ArgumentNullException(nameof(package));
ArgumentNullException.ThrowIfNull(package);
map.Save(package);

View File

@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
this.worldRenderer = worldRenderer;
MiniYaml yaml;
var keyNames = Enum.GetNames(typeof(ObserverStatsPanel));
var keyNames = Enum.GetNames<ObserverStatsPanel>();
var statsHotkeys = new HotkeyReference[keyNames.Length];
for (var i = 0; i < keyNames.Length; i++)
statsHotkeys[i] = logicArgs.TryGetValue("Statistics" + keyNames[i] + "Key", out yaml) ? modData.Hotkeys[yaml.Value] : new HotkeyReference();

View File

@@ -321,7 +321,7 @@ namespace OpenRA.Mods.Common.Widgets
if (e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition < Text.Length)
{
// Write directly to the Text backing field to avoid unnecessary validation
text = text.Remove(CursorPosition);
text = text[..CursorPosition];
CursorPosition = CursorPosition.Clamp(0, text.Length);
OnTextEdited();
@@ -379,7 +379,7 @@ namespace OpenRA.Mods.Common.Widgets
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
text = text[..CursorPosition] + text[GetNextWhitespaceIndex()..];
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
text = text.Remove(CursorPosition);
text = text[..CursorPosition];
else
text = text.Remove(CursorPosition, 1);