diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerVerb.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerVerb.cs index ce205d5388721b..f4000a570dd7ee 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerVerb.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerVerb.cs @@ -22,11 +22,11 @@ public DesignerVerb(string text, EventHandler handler) : this(text, handler, Sta /// public DesignerVerb(string text, EventHandler handler, CommandID startCommandID) : base(handler, startCommandID) { - Properties["Text"] = text == null ? null : GetParameterReplacementRegex().Replace(text, ""); + Properties["Text"] = text == null ? null : ParameterReplacementRegex.Replace(text, ""); } [GeneratedRegex(@"\(\&.\)")] - private static partial Regex GetParameterReplacementRegex(); + private static partial Regex ParameterReplacementRegex { get; } /// /// Gets or sets the description of the menu item for the verb. diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs index 79bfc1a51f2a14..371dd171255648 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs @@ -2234,7 +2234,7 @@ internal static bool IsAssemblyFriendOfSerialization(Assembly assembly) string internalsVisibleAttributeAssemblyName = internalsVisibleAttribute.AssemblyName; if (internalsVisibleAttributeAssemblyName.Trim().Equals("System.Runtime.Serialization") || - Globals.FullSRSInternalsVisibleRegex().IsMatch(internalsVisibleAttributeAssemblyName)) + Globals.FullSRSInternalsVisibleRegex.IsMatch(internalsVisibleAttributeAssemblyName)) { return true; } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Globals.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Globals.cs index 7c1c65e2d97967..65e88a4ac221b4 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Globals.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Globals.cs @@ -347,7 +347,7 @@ internal static Type TypeOfHashtable public const string NullObjectId = null; public const string FullSRSInternalsVisiblePattern = @"^[\s]*System\.Runtime\.Serialization[\s]*,[\s]*PublicKey[\s]*=[\s]*(?i:00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab)[\s]*$"; [GeneratedRegex(FullSRSInternalsVisiblePattern)] - public static partial Regex FullSRSInternalsVisibleRegex(); + public static partial Regex FullSRSInternalsVisibleRegex { get; } public const char SpaceChar = ' '; public const char OpenBracketChar = '['; public const char CloseBracketChar = ']'; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs index 3c1c57254bc59c..091b42616e8809 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs @@ -1342,7 +1342,7 @@ internal sealed partial class StringFacetsChecker : FacetsChecker { //All types derived from string & anyURI [GeneratedRegex("^([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*$", RegexOptions.ExplicitCapture)] - private static partial Regex LanguageRegex(); + private static partial Regex LanguageRegex { get; } internal override Exception? CheckValueFacets(object value, XmlSchemaDatatype datatype) { @@ -1456,7 +1456,7 @@ private static bool MatchEnumeration(string value, ArrayList enumeration, XmlSch { return new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty); } - if (!LanguageRegex().IsMatch(s)) + if (!LanguageRegex.IsMatch(s)) { return new XmlSchemaException(SR.Sch_InvalidLanguageId, string.Empty); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs index 3a544fb9dcd954..37c5eb192b6a3c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs @@ -16,11 +16,11 @@ internal sealed partial class SourceInfo //a[ia] //((global::System.Xml.Serialization.XmlSerializerNamespaces)p[0]) [GeneratedRegex("([(][(](?[^)]+)[)])?(?[^[]+)[[](?.+)[]][)]?")] - private static partial Regex Regex1(); + private static partial Regex Regex1 { get; } //((global::Microsoft.CFx.Test.Common.TypeLibrary.IXSType_9)o), @"IXSType_9", @"", true, true); [GeneratedRegex("[(][(](?[^)]+)[)](?[^)]+)[)]")] - private static partial Regex Regex2(); + private static partial Regex Regex2 { get; } private static readonly Lazy s_iListGetItemMethod = new Lazy( () => @@ -69,7 +69,7 @@ public void Load(Type? elementType) [RequiresUnreferencedCode("calls LoadMemberAddress")] private void InternalLoad(Type? elementType, bool asAddress = false) { - Match match = Regex1().Match(Arg); + Match match = Regex1.Match(Arg); if (match.Success) { object varA = ILG.GetVariable(match.Groups["a"].Value); @@ -190,7 +190,7 @@ private void InternalLoad(Type? elementType, bool asAddress = false) } else { - match = Regex2().Match(Source); + match = Regex2.Match(Source); if (match.Success) { Debug.Assert(match.Groups["arg"].Value == Arg); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs index 625092e2936747..feaa93a2e1f59a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs @@ -2708,10 +2708,10 @@ private void WriteSourceBeginTyped(string source) } [GeneratedRegex("(?[^ ]+) = .+EnsureArrayIndex[(](?[^,]+), (?[^,]+),[^;]+;(?[^[]+)[[](?[^+]+)[+][+][]]")] - private static partial Regex EnsureArrayIndexRegex(); + private static partial Regex EnsureArrayIndexRegex { get; } [GeneratedRegex("(?[^[]+)[[](?.+)[]]")] - private static partial Regex P0Regex(); + private static partial Regex P0Regex { get; } private void WriteSourceBegin(string source) { @@ -2733,7 +2733,7 @@ private void WriteSourceBegin(string source) return; } // a_0_0 = (global::System.Object[])EnsureArrayIndex(a_0_0, ca_0_0, typeof(global::System.Object));a_0_0[ca_0_0++] - Match match = EnsureArrayIndexRegex().Match(source); + Match match = EnsureArrayIndexRegex.Match(source); if (match.Success) { Debug.Assert(match.Groups["locA1"].Value == match.Groups["locA2"].Value); @@ -2779,7 +2779,7 @@ private void WriteSourceBegin(string source) } // p[0] - match = P0Regex().Match(source); + match = P0Regex.Match(source); if (match.Success) { System.Diagnostics.Debug.Assert(CodeGenerator.GetVariableType(ilg.GetVariable(match.Groups["a"].Value)).IsArray); @@ -2825,7 +2825,7 @@ private void WriteSourceEnd(string source, Type elementType, Type stackType) return; } // a_0_0 = (global::System.Object[])EnsureArrayIndex(a_0_0, ca_0_0, typeof(global::System.Object));a_0_0[ca_0_0++] - Match match = EnsureArrayIndexRegex().Match(source); + Match match = EnsureArrayIndexRegex.Match(source); if (match.Success) { object oVar = ilg.GetVariable(match.Groups["locA1"].Value); @@ -2861,7 +2861,7 @@ private void WriteSourceEnd(string source, Type elementType, Type stackType) return; } // p[0] - match = P0Regex().Match(source); + match = P0Regex.Match(source); if (match.Success) { Type varType = CodeGenerator.GetVariableType(ilg.GetVariable(match.Groups["a"].Value)); @@ -3528,19 +3528,19 @@ private static void WriteLocalDecl(string variableName, SourceInfo initValue) } [GeneratedRegex("UnknownNode[(]null, @[\"](?[^\"]*)[\"][)];")] - private static partial Regex UnknownNodeNullAnyTypeRegex(); + private static partial Regex UnknownNodeNullAnyTypeRegex { get; } [GeneratedRegex("UnknownNode[(][(]object[)](?[^,]+), @[\"](?[^\"]*)[\"][)];")] - private static partial Regex UnknownNodeObjectEmptyRegex(); + private static partial Regex UnknownNodeObjectEmptyRegex { get; } [GeneratedRegex("UnknownNode[(][(]object[)](?[^,]+), null[)];")] - private static partial Regex UnknownNodeObjectNullRegex(); + private static partial Regex UnknownNodeObjectNullRegex { get; } [GeneratedRegex("UnknownNode[(][(]object[)](?[^)]+)[)];")] - private static partial Regex UnknownNodeObjectRegex(); + private static partial Regex UnknownNodeObjectRegex { get; } [GeneratedRegex("paramsRead\\[(?[0-9]+)\\]")] - private static partial Regex ParamsReadRegex(); + private static partial Regex ParamsReadRegex { get; } private void ILGenElseString(string elseString) { @@ -3555,7 +3555,7 @@ private void ILGenElseString(string elseString) new Type[] { typeof(object), typeof(string) } )!; // UnknownNode(null, @":anyType"); - Match match = UnknownNodeNullAnyTypeRegex().Match(elseString); + Match match = UnknownNodeNullAnyTypeRegex.Match(elseString); if (match.Success) { ilg.Ldarg(0); @@ -3565,7 +3565,7 @@ private void ILGenElseString(string elseString) return; } // UnknownNode((object)o, @""); - match = UnknownNodeObjectEmptyRegex().Match(elseString); + match = UnknownNodeObjectEmptyRegex.Match(elseString); if (match.Success) { ilg.Ldarg(0); @@ -3577,7 +3577,7 @@ private void ILGenElseString(string elseString) return; } // UnknownNode((object)o, null); - match = UnknownNodeObjectNullRegex().Match(elseString); + match = UnknownNodeObjectNullRegex.Match(elseString); if (match.Success) { ilg.Ldarg(0); @@ -3589,7 +3589,7 @@ private void ILGenElseString(string elseString) return; } // "UnknownNode((object)o);" - match = UnknownNodeObjectRegex().Match(elseString); + match = UnknownNodeObjectRegex.Match(elseString); if (match.Success) { ilg.Ldarg(0); @@ -3603,7 +3603,7 @@ private void ILGenElseString(string elseString) } private void ILGenParamsReadSource(string paramsReadSource) { - Match match = ParamsReadRegex().Match(paramsReadSource); + Match match = ParamsReadRegex.Match(paramsReadSource); if (match.Success) { ilg.Ldloca(ilg.GetLocal("paramsRead")); @@ -3616,7 +3616,7 @@ private void ILGenParamsReadSource(string paramsReadSource) } private void ILGenParamsReadSource(string paramsReadSource, bool value) { - Match match = ParamsReadRegex().Match(paramsReadSource); + Match match = ParamsReadRegex.Match(paramsReadSource); if (match.Success) { ilg.Ldloca(ilg.GetLocal("paramsRead")); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs b/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs index 59e3b3b4ae891e..efe07812b079cf 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs @@ -86,7 +86,7 @@ public partial class XmlConvert return name; } - Regex.ValueMatchEnumerator en = DecodeCharRegex().EnumerateMatches(name.AsSpan(underscorePos)); + Regex.ValueMatchEnumerator en = DecodeCharRegex.EnumerateMatches(name.AsSpan(underscorePos)); int matchPos = -1; if (en.MoveNext()) { @@ -185,7 +185,7 @@ public partial class XmlConvert IEnumerator? en = null; if (underscorePos >= 0) { - mc = EncodeCharRegex().Matches(name, underscorePos); + mc = EncodeCharRegex.Matches(name, underscorePos); en = mc.GetEnumerator(); } @@ -281,10 +281,10 @@ public partial class XmlConvert private const int EncodedCharLength = 7; // ("_xFFFF_".Length); [GeneratedRegex("_[Xx][0-9a-fA-F]{4}(?:_|[0-9a-fA-F]{4}_)")] - private static partial Regex DecodeCharRegex(); + private static partial Regex DecodeCharRegex { get; } [GeneratedRegex("(?<=_)[Xx][0-9a-fA-F]{4}(?:_|[0-9a-fA-F]{4}_)")] - private static partial Regex EncodeCharRegex(); + private static partial Regex EncodeCharRegex { get; } private static int FromHex(char digit) { diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/TimeZoneInfoTests.cs index 6489a44ac0ea6c..380600d79015dc 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/TimeZoneInfoTests.cs @@ -2434,10 +2434,8 @@ public static IEnumerable SystemTimeZonesTestData() } } - private const string IanaAbbreviationPattern = @"^(?:[A-Z][A-Za-z]+|[+-]\d{2}|[+-]\d{4})$"; - - [GeneratedRegex(IanaAbbreviationPattern)] - private static partial Regex IanaAbbreviationRegex(); + [GeneratedRegex(@"^(?:[A-Z][A-Za-z]+|[+-]\d{2}|[+-]\d{4})$")] + private static partial Regex IanaAbbreviationRegex { get; } // UTC aliases per https://github.com/unicode-org/cldr/blob/master/common/bcp47/timezone.xml // (This list is not likely to change.) @@ -2487,10 +2485,10 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) else { // For other time zones, match any valid IANA time zone abbreviation, including numeric forms - Assert.True(IanaAbbreviationRegex().IsMatch(timeZone.StandardName), - $"Id: \"{timeZone.Id}\", StandardName should have matched the pattern @\"{IanaAbbreviationPattern}\", Actual StandardName: \"{timeZone.StandardName}\""); - Assert.True(IanaAbbreviationRegex().IsMatch(timeZone.DaylightName), - $"Id: \"{timeZone.Id}\", DaylightName should have matched the pattern @\"{IanaAbbreviationPattern}\", Actual DaylightName: \"{timeZone.DaylightName}\""); + Assert.True(IanaAbbreviationRegex.IsMatch(timeZone.StandardName), + $"Id: \"{timeZone.Id}\", StandardName should have matched the pattern @\"{IanaAbbreviationRegex}\", Actual StandardName: \"{timeZone.StandardName}\""); + Assert.True(IanaAbbreviationRegex.IsMatch(timeZone.DaylightName), + $"Id: \"{timeZone.Id}\", DaylightName should have matched the pattern @\"{IanaAbbreviationRegex}\", Actual DaylightName: \"{timeZone.DaylightName}\""); } } else if (isUtc)