diff --git a/src/Umbraco.Cms.Api.Management/ServerEvents/UserConnectionManager.cs b/src/Umbraco.Cms.Api.Management/ServerEvents/UserConnectionManager.cs index 69bcd284e8..c5479e604b 100644 --- a/src/Umbraco.Cms.Api.Management/ServerEvents/UserConnectionManager.cs +++ b/src/Umbraco.Cms.Api.Management/ServerEvents/UserConnectionManager.cs @@ -7,7 +7,7 @@ internal sealed class UserConnectionManager : IUserConnectionManager { // We use a normal dictionary instead of ConcurrentDictionary, since we need to lock the set anyways. private readonly Dictionary> _connections = new(); - private readonly object _lock = new(); + private readonly Lock _lock = new(); /// public ISet GetConnections(Guid userKey) diff --git a/src/Umbraco.Core/Extensions/StringExtensions.cs b/src/Umbraco.Core/Extensions/StringExtensions.cs index 7f3cbbd66b..205eb723d4 100644 --- a/src/Umbraco.Core/Extensions/StringExtensions.cs +++ b/src/Umbraco.Core/Extensions/StringExtensions.cs @@ -5,7 +5,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; diff --git a/src/Umbraco.Core/Routing/SiteDomainMapper.cs b/src/Umbraco.Core/Routing/SiteDomainMapper.cs index 247319cd5a..496bd6fe43 100644 --- a/src/Umbraco.Core/Routing/SiteDomainMapper.cs +++ b/src/Umbraco.Core/Routing/SiteDomainMapper.cs @@ -65,7 +65,7 @@ namespace Umbraco.Cms.Core.Routing } } - private IEnumerable ValidateDomains(IEnumerable domains) => + private static IEnumerable ValidateDomains(IEnumerable domains) => // must use authority format w/optional scheme and port, but no path // any domain should appear only once domains.Select(domain => @@ -368,7 +368,7 @@ namespace Umbraco.Cms.Core.Routing // therefore it is safe to return and exit the configuration lock } - private DomainAndUri? MapDomain( + private static DomainAndUri? MapDomain( IReadOnlyCollection domainAndUris, Dictionary? qualifiedSites, string currentAuthority, diff --git a/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs b/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs index de573d23d1..4714ebcd2e 100644 --- a/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs +++ b/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs @@ -1,7 +1,6 @@ using System.Globalization; using System.Text.RegularExpressions; using Umbraco.Cms.Core.Routing; -using Umbraco.Cms.Core.Web; namespace Umbraco.Cms.Core.Templates; @@ -84,7 +83,7 @@ public sealed class HtmlLocalLinkParser // under normal circumstances, the type attribute is preceded by a space // to cover the rare occasion where it isn't, we first replace with a space and then without. - private string StripTypeAttributeFromTag(string tag, string type) => + private static string StripTypeAttributeFromTag(string tag, string type) => tag.Replace($" type=\"{type}\"", string.Empty) .Replace($"type=\"{type}\"", string.Empty); diff --git a/src/Umbraco.Web.Common/Filters/ModelBindingExceptionAttribute.cs b/src/Umbraco.Web.Common/Filters/ModelBindingExceptionAttribute.cs index 4b7f0a17b7..a4feac6f7d 100644 --- a/src/Umbraco.Web.Common/Filters/ModelBindingExceptionAttribute.cs +++ b/src/Umbraco.Web.Common/Filters/ModelBindingExceptionAttribute.cs @@ -85,7 +85,7 @@ public sealed class ModelBindingExceptionAttribute : TypeFilterAttribute /// The application is in an unstable state and is going to be restarted. The application is restarting now. /// /// - private bool IsMessageAboutTheSameModelType(string exceptionMessage) + private static bool IsMessageAboutTheSameModelType(string exceptionMessage) { MatchCollection matches = GetPublishedModelsTypesRegex.Matches(exceptionMessage); diff --git a/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs b/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs index cee000e7f9..78c1b808a5 100644 --- a/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs +++ b/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Frozen; using System.Reflection; using System.Reflection.Emit; using System.Text; @@ -21,12 +22,24 @@ using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; namespace Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto { - internal sealed class InMemoryModelFactory : IAutoPublishedModelFactory, IRegisteredObject, IDisposable + internal sealed partial class InMemoryModelFactory : IAutoPublishedModelFactory, IRegisteredObject, IDisposable { - private static readonly Regex s_usingRegex = new Regex("^using(.*);", RegexOptions.Compiled | RegexOptions.Multiline); - private static readonly Regex s_aattrRegex = new Regex("^\\[assembly:(.*)\\]", RegexOptions.Compiled | RegexOptions.Multiline); - private static readonly Regex s_assemblyVersionRegex = new Regex("AssemblyVersion\\(\"[0-9]+.[0-9]+.[0-9]+.[0-9]+\"\\)", RegexOptions.Compiled); - private static readonly string[] s_ourFiles = { "models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err", "Compiled" }; + private static readonly Regex s_usingRegex = GetUsingRegex(); + + [GeneratedRegex("^using(.*);", RegexOptions.Multiline | RegexOptions.Compiled)] + private static partial Regex GetUsingRegex(); + + private static readonly Regex s_aattrRegex = GetAssemblyRegex(); + + [GeneratedRegex("^\\[assembly:(.*)\\]", RegexOptions.Multiline | RegexOptions.Compiled)] + private static partial Regex GetAssemblyRegex(); + + private static readonly Regex s_assemblyVersionRegex = GetAssemblyVersionRegex(); + + [GeneratedRegex("AssemblyVersion\\(\"[0-9]+.[0-9]+.[0-9]+.[0-9]+\"\\)", RegexOptions.Compiled)] + private static partial Regex GetAssemblyVersionRegex(); + + private static readonly FrozenSet s_ourFiles = FrozenSet.Create("models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err", "Compiled"); private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim(); private readonly IProfilingLogger _profilingLogger; private readonly ILogger _logger; @@ -797,7 +810,7 @@ namespace Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto // } // always ignore our own file changes - if (s_ourFiles.Contains(changed)) + if (changed != null && s_ourFiles.Contains(changed)) { return; }