use target-typed new

This commit is contained in:
Jesse Plamondon-Willard
2025-03-09 11:42:32 -04:00
parent 68c4884d63
commit de6ccb0d01
14 changed files with 18 additions and 18 deletions
@@ -39,7 +39,7 @@ internal class ContentPackFileManager : IModFileManager
public ContentPackFileManager(string projectDir, string contentPackDir, string version, string[] ignoreFilePaths, Regex[] ignoreFilePatterns, bool validateManifest)
{
// get folders
DirectoryInfo projectDirInfo = new DirectoryInfo(Path.Combine(projectDir, contentPackDir));
DirectoryInfo projectDirInfo = new(Path.Combine(projectDir, contentPackDir));
if (!projectDirInfo.Exists)
throw GetError($"that folder doesn't exist at {projectDirInfo.FullName}");
@@ -251,7 +251,7 @@ internal class ItemRepository
{
try
{
SearchableItem item = new SearchableItem(type, key, createItem);
SearchableItem item = new(type, key, createItem);
item.Item.getDescription(); // force-load item data, so it crashes here if it's invalid
if (item.Item.Name is null or "Error Item")
@@ -105,7 +105,7 @@ public class SimpleApi : BaseApi
outReference = new PerScreen<int>(() => inputNumber);
outComplexType = new Dictionary<int, PerScreen<int>>
{
[inputNumber] = new PerScreen<int>(() => inputNumber)
[inputNumber] = new(() => inputNumber)
};
return true;
@@ -108,7 +108,7 @@ public class ChangeDescriptor
// add values
if (this.Add.Any())
{
HashSet<string> curValues = new HashSet<string>(values.Select(p => p.Trim()), StringComparer.OrdinalIgnoreCase);
HashSet<string> curValues = new(values.Select(p => p.Trim()), StringComparer.OrdinalIgnoreCase);
foreach (string add in this.Add)
{
if (!curValues.Contains(add))
@@ -126,7 +126,7 @@ public class ChangeDescriptor
if (!this.HasChanges)
return string.Empty;
List<string> descriptors = new List<string>(this.Add.Count + this.Remove.Count + this.Replace.Count);
List<string> descriptors = new(this.Add.Count + this.Remove.Count + this.Replace.Count);
foreach (string add in this.Add)
descriptors.Add($"+{add}");
foreach (string remove in this.Remove)
@@ -54,7 +54,7 @@ public static class ManifestValidator
// validate required fields
{
List<string> missingFields = new List<string>(3);
List<string> missingFields = new(3);
if (string.IsNullOrWhiteSpace(manifest.Name))
missingFields.Add(nameof(IManifest.Name));
@@ -21,9 +21,9 @@ public class ModScanner
/// <summary>A list of filesystem entry names to ignore when checking whether a folder should be treated as a mod.</summary>
private readonly HashSet<Regex> IgnoreFilesystemNames =
[
new Regex(@"^__folder_managed_by_vortex$", RegexOptions.Compiled | RegexOptions.IgnoreCase), // Vortex mod manager
new Regex(@"(?:^\._|^\.DS_Store$|^__MACOSX$|^mcs$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), // macOS
new Regex(@"^(?:desktop\.ini|Thumbs\.db)$", RegexOptions.Compiled | RegexOptions.IgnoreCase)
new(@"^__folder_managed_by_vortex$", RegexOptions.Compiled | RegexOptions.IgnoreCase), // Vortex mod manager
new(@"(?:^\._|^\.DS_Store$|^__MACOSX$|^mcs$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), // macOS
new(@"^(?:desktop\.ini|Thumbs\.db)$", RegexOptions.Compiled | RegexOptions.IgnoreCase)
];
/// <summary>A list of file extensions to ignore when searching for mod files.</summary>
@@ -95,7 +95,7 @@ internal class LogParserController : Controller
// note: avoid this.Request.Form, which fails if any mod logged a null character.
string? input;
{
using StreamReader reader = new StreamReader(this.Request.Body);
using StreamReader reader = new(this.Request.Body);
NameValueCollection parsed = HttpUtility.ParseQueryString(await reader.ReadToEndAsync());
input = parsed["input"];
if (string.IsNullOrWhiteSpace(input))
+2 -2
View File
@@ -74,7 +74,7 @@ internal sealed class SInputState : InputState
var mouse = new MouseStateBuilder(base.GetMouseState());
Vector2 cursorAbsolutePos = new((mouse.X * zoomMultiplier) + Game1.viewport.X, (mouse.Y * zoomMultiplier) + Game1.viewport.Y);
Vector2? playerTilePos = Context.IsPlayerFree ? Game1.player.Tile : null;
HashSet<SButton> reallyDown = new HashSet<SButton>(this.GetPressedButtons(keyboard, mouse, controller));
HashSet<SButton> reallyDown = new(this.GetPressedButtons(keyboard, mouse, controller));
// apply overrides
bool hasOverrides = false;
@@ -94,7 +94,7 @@ internal sealed class SInputState : InputState
// get button states
var pressedButtons = hasOverrides
? new HashSet<SButton>(this.GetPressedButtons(keyboard, mouse, controller))
? new(this.GetPressedButtons(keyboard, mouse, controller))
: reallyDown;
var activeButtons = this.DeriveStates(this.ButtonStates, pressedButtons);
@@ -12,7 +12,7 @@ internal class InventoryToNetObjectList : NetObjectList<Item>
** Fields
*********/
/// <summary>A cached lookup of inventory wrappers.</summary>
private static readonly Dictionary<Inventory, InventoryToNetObjectList> CachedWrappers = new Dictionary<Inventory, InventoryToNetObjectList>(ReferenceEqualityComparer.Instance);
private static readonly Dictionary<Inventory, InventoryToNetObjectList> CachedWrappers = new(ReferenceEqualityComparer.Instance);
/// <summary>The underlying inventory to track.</summary>
private readonly Inventory Inventory;
@@ -38,7 +38,7 @@ public abstract class NpcFacade : NPC, IRewriteFacade
public static NPC Constructor(AnimatedSprite sprite, Vector2 position, string defaultMap, int facingDir, string name, Dictionary<int, int[]> schedule, Texture2D portrait, bool eventActor, string? syncedPortraitPath = null)
{
NPC npc = new NPC(sprite, position, defaultMap, facingDir, name, portrait, eventActor);
NPC npc = new(sprite, position, defaultMap, facingDir, name, portrait, eventActor);
if (!string.IsNullOrWhiteSpace(syncedPortraitPath))
{
@@ -110,7 +110,7 @@ internal class TypeReferenceComparer : IEqualityComparer<TypeReference?>
{
int openGenerics = 0;
Queue<char> queue = new Queue<char>(typeName);
Queue<char> queue = new(typeName);
string symbol = "";
while (queue.Any())
{
+1 -1
View File
@@ -442,7 +442,7 @@ internal class SCore : IDisposable
// apply load order customizations
if (this.Settings.ModsToLoadEarly.Any() || this.Settings.ModsToLoadLate.Any())
{
HashSet<string> installedIds = new HashSet<string>(mods.Select(p => p.Manifest?.UniqueID).Where(p => p is not null)!, StringComparer.OrdinalIgnoreCase);
HashSet<string> installedIds = new(mods.Select(p => p.Manifest?.UniqueID).Where(p => p is not null)!, StringComparer.OrdinalIgnoreCase);
string[] missingEarlyMods = this.Settings.ModsToLoadEarly.Where(id => !installedIds.Contains(id)).OrderBy(p => p, StringComparer.OrdinalIgnoreCase).ToArray();
string[] missingLateMods = this.Settings.ModsToLoadLate.Where(id => !installedIds.Contains(id)).OrderBy(p => p, StringComparer.OrdinalIgnoreCase).ToArray();
+1 -1
View File
@@ -502,7 +502,7 @@ internal class SMultiplayer : Multiplayer
}
// get player IDs
HashSet<long> playerIds = new HashSet<long>(model.ToPlayerIds ?? this.GetKnownPlayerIds());
HashSet<long> playerIds = new(model.ToPlayerIds ?? this.GetKnownPlayerIds());
// notify local mods
if (playerIds.Contains(Game1.player.UniqueMultiplayerID))
@@ -187,7 +187,7 @@ static class MiniMonoModHotfix
private static void _FixReflectionCacheOrder<T>(Array orig) where T : MemberInfo
{
// Sort using a short-lived list.
List<T> list = new List<T>(orig.Length);
List<T> list = new(orig.Length);
for (int i = 0; i < orig.Length; i++)
list.Add((T)orig.GetValue(i)!);