@@ -834,19 +834,23 @@ internal sealed partial class MonoSDBHelper
834834
835835 internal readonly ILogger logger ;
836836
837- #pragma warning disable SYSLIB1045
838- private static Regex regexForAsyncLocals = new ( @"\<(?<varName>[^)]*)\>(?<varId>[^)]*)(__)(?<scopeId>\d+)" , RegexOptions . Singleline ) ;
837+ [ GeneratedRegex ( @"\<(?<varName>[^)]*)\>(?<varId>[^)]*)(__)(?<scopeId>\d+)" , RegexOptions . Singleline ) ]
838+ private static partial Regex RegexForAsyncLocals ( ) ; //<testCSharpScope>5__1 // works
839839
840- private static Regex regexForVBAsyncLocals = new ( @"\$VB\$ResumableLocal_(?<varName>[^\$]*)\$(?<scopeId>\d+)" , RegexOptions . Singleline ) ; //$VB$ResumableLocal_testVbScope$2
840+ [ GeneratedRegex ( @"\$VB\$ResumableLocal_(?<varName>[^\$]*)\$(?<scopeId>\d+)" , RegexOptions . Singleline ) ]
841+ private static partial Regex RegexForVBAsyncLocals ( ) ; //$VB$ResumableLocal_testVbScope$2
841842
842- private static Regex regexForVBAsyncMethodName = new ( @"VB\$StateMachine_(\d+)_(?<methodName>.*)" , RegexOptions . Singleline ) ; //VB$StateMachine_2_RunVBScope
843+ [ GeneratedRegex ( @"VB\$StateMachine_(\d+)_(?<methodName>.*)" , RegexOptions . Singleline ) ]
844+ private static partial Regex RegexForVBAsyncMethodName ( ) ; //VB$StateMachine_2_RunVBScope
843845
844- private static Regex regexForAsyncMethodName = new ( @"\<([^>]*)\>([d][_][_])([0-9]*)" ) ;
846+ [ GeneratedRegex ( @"\<([^>]*)\>([d][_][_])([0-9]*)" ) ]
847+ private static partial Regex RegexForAsyncMethodName ( ) ;
845848
846- private static Regex regexForGenericArgs = new ( @"[`][0-9]+" ) ;
849+ [ GeneratedRegex ( @"[`][0-9]+" ) ]
850+ private static partial Regex RegexForGenericArgs ( ) ;
847851
848- private static Regex regexForNestedLeftRightAngleBrackets = new ( "^(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*(?(Open)(?!))[^<>]*" ) ; // <ContinueWithStaticAsync>b__3_0
849- #pragma warning restore SYSLIB1045
852+ [ GeneratedRegex ( "^(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*(?(Open)(?!))[^<>]*" ) ]
853+ private static partial Regex RegexForNestedLeftRightAngleBrackets ( ) ; // <ContinueWithStaticAsync>b__3_0
850854
851855 public JObjectValueCreator ValueCreator { get ; init ; }
852856
@@ -922,7 +926,7 @@ public static string GetPrettierMethodName(string methodName)
922926 {
923927 methodName = methodName . Replace ( ':' , '.' ) ;
924928 methodName = methodName . Replace ( '/' , '.' ) ;
925- methodName = regexForGenericArgs . Replace ( methodName , "" ) ;
929+ methodName = RegexForGenericArgs ( ) . Replace ( methodName , "" ) ;
926930 return methodName ;
927931 }
928932
@@ -1304,25 +1308,25 @@ public async Task<string> GetPrettyMethodName(int methodId, bool isAnonymous, Ca
13041308 var ret = retDebuggerCmdReader . ReadString ( ) ;
13051309 if ( ret . IndexOf ( ':' ) is int index && index > 0 )
13061310 ret = ret . Substring ( 0 , index ) ;
1307- ret = regexForAsyncMethodName . Replace ( ret , "$1" ) ;
1311+ ret = RegexForAsyncMethodName ( ) . Replace ( ret , "$1" ) ;
13081312 var numGenericTypeArgs = retDebuggerCmdReader . ReadInt32 ( ) ;
13091313 var numGenericMethodArgs = retDebuggerCmdReader . ReadInt32 ( ) ;
13101314 int numTotalGenericArgs = numGenericTypeArgs + numGenericMethodArgs ;
13111315 var genericArgs = new List < string > ( capacity : numTotalGenericArgs ) ;
13121316 for ( int i = 0 ; i < numTotalGenericArgs ; i ++ )
13131317 {
13141318 var typeArgC = retDebuggerCmdReader . ReadString ( ) ;
1315- typeArgC = regexForGenericArgs . Replace ( typeArgC , "" ) ;
1319+ typeArgC = RegexForGenericArgs ( ) . Replace ( typeArgC , "" ) ;
13161320 genericArgs . Add ( typeArgC ) ;
13171321 }
1318- var match = regexForGenericArgs . Match ( ret ) ;
1322+ var match = RegexForGenericArgs ( ) . Match ( ret ) ;
13191323 while ( match . Success )
13201324 {
13211325 var countArgs = Convert . ToInt32 ( match . Value . Remove ( 0 , 1 ) ) ;
13221326 ret = ret . Remove ( match . Index , match . Value . Length ) ;
13231327 ret = ret . Insert ( match . Index , $ "<{ string . Join ( ", " , genericArgs . Take ( countArgs ) ) } >") ;
13241328 genericArgs . RemoveRange ( 0 , countArgs ) ;
1325- match = regexForGenericArgs . Match ( ret ) ;
1329+ match = RegexForGenericArgs ( ) . Match ( ret ) ;
13261330 }
13271331 ret = ret . Replace ( '/' , '.' ) ;
13281332 return ret ;
@@ -1342,15 +1346,15 @@ public async Task<string> GetPrettyMethodName(int methodId, bool isAnonymous, Ca
13421346 }
13431347 else if ( klassName . StartsWith ( "VB$" ) )
13441348 {
1345- var match = regexForVBAsyncMethodName . Match ( klassName ) ;
1349+ var match = RegexForVBAsyncMethodName ( ) . Match ( klassName ) ;
13461350 if ( match . Success )
13471351 ret = ret . Insert ( 0 , match . Groups [ "methodName" ] . Value ) ;
13481352 else
13491353 ret = ret . Insert ( 0 , klassName ) ;
13501354 }
13511355 else
13521356 {
1353- var matchOnClassName = regexForNestedLeftRightAngleBrackets . Match ( klassName ) ;
1357+ var matchOnClassName = RegexForNestedLeftRightAngleBrackets ( ) . Match ( klassName ) ;
13541358 if ( matchOnClassName . Success && matchOnClassName . Groups [ "Close" ] . Captures . Count > 0 )
13551359 klassName = matchOnClassName . Groups [ "Close" ] . Captures [ 0 ] . Value ;
13561360 if ( ret . Length > 0 )
@@ -1359,7 +1363,7 @@ public async Task<string> GetPrettyMethodName(int methodId, bool isAnonymous, Ca
13591363 }
13601364 }
13611365 var methodName = retDebuggerCmdReader . ReadString ( ) ;
1362- var matchOnMethodName = regexForNestedLeftRightAngleBrackets . Match ( methodName ) ;
1366+ var matchOnMethodName = RegexForNestedLeftRightAngleBrackets ( ) . Match ( methodName ) ;
13631367 if ( matchOnMethodName . Success && matchOnMethodName . Groups [ "Close" ] . Captures . Count > 0 )
13641368 {
13651369 if ( isAnonymous && anonymousMethodId . Length == 0 && methodName . Contains ( "__" ) )
@@ -1712,17 +1716,19 @@ public async Task<string> GetValueFromDebuggerDisplayAttribute(DotnetObjectId do
17121716 }
17131717 return null ;
17141718 }
1715- #pragma warning disable SYSLIB1045
1716- private static Regex regexForGenericArity = new ( @"`\d+" ) ;
1717- private static Regex regexForSquareBrackets = new ( @"[[, ]+]" ) ;
1718- #pragma warning restore SYSLIB1045
1719+
1720+ [ GeneratedRegex ( @"`\d+" ) ]
1721+ private static partial Regex RegexForGenericArity ( ) ;
1722+
1723+ [ GeneratedRegex ( @"[[, ]+]" ) ]
1724+ private static partial Regex RegexForSquareBrackets ( ) ;
17191725
17201726 public async Task < string > GetTypeName ( int typeId , CancellationToken token )
17211727 {
17221728 string className = await GetTypeNameOriginal ( typeId , token ) ;
17231729 className = className . Replace ( "+" , "." ) ;
1724- className = regexForGenericArity . Replace ( className , "" ) ;
1725- className = regexForSquareBrackets . Replace ( className , "__SQUARED_BRACKETS__" ) ;
1730+ className = RegexForGenericArity ( ) . Replace ( className , "" ) ;
1731+ className = RegexForSquareBrackets ( ) . Replace ( className , "__SQUARED_BRACKETS__" ) ;
17261732 //className = className.Replace("[]", "__SQUARED_BRACKETS__");
17271733 className = className . Replace ( "[" , "<" ) ;
17281734 className = className . Replace ( "]" , ">" ) ;
@@ -2065,7 +2071,7 @@ public async Task<JArray> GetHoistedLocalVariables(MethodInfoWithDebugInformatio
20652071 }
20662072 else if ( fieldName . StartsWith ( '<' ) ) //examples: <code>5__2
20672073 {
2068- var match = regexForAsyncLocals . Match ( fieldName ) ;
2074+ var match = RegexForAsyncLocals ( ) . Match ( fieldName ) ;
20692075 if ( match . Success )
20702076 {
20712077 if ( ! method . Info . ContainsAsyncScope ( Convert . ToInt32 ( match . Groups [ "scopeId" ] . Value ) , offset ) )
@@ -2080,7 +2086,7 @@ public async Task<JArray> GetHoistedLocalVariables(MethodInfoWithDebugInformatio
20802086 }
20812087 else if ( fieldName . StartsWith ( "$VB$ResumableLocal_" , StringComparison . Ordinal ) )
20822088 {
2083- var match = regexForVBAsyncLocals . Match ( fieldName ) ;
2089+ var match = RegexForVBAsyncLocals ( ) . Match ( fieldName ) ;
20842090 if ( match . Success )
20852091 {
20862092 if ( ! method . Info . ContainsAsyncScope ( Convert . ToInt32 ( match . Groups [ "scopeId" ] . Value ) + 1 , offset ) )
0 commit comments