@@ -823,8 +823,9 @@ public static bool EndsWithInvariant(this string str, string endsWith)
823823 return str . EndsWith ( endsWith , PclExport . Instance . InvariantComparison ) ;
824824 }
825825
826- private static readonly Regex InvalidVarCharsRegex = new Regex ( @"[^A-Za-z0-9]" , PclExport . Instance . RegexOptions ) ;
827- private static readonly Regex SplitCamelCaseRegex = new Regex ( "([A-Z]|[0-9]+)" , PclExport . Instance . RegexOptions ) ;
826+ private static readonly Regex InvalidVarCharsRegex = new Regex ( @"[^A-Za-z0-9_]" , RegexOptions . Compiled ) ;
827+ private static readonly Regex InvalidVarRefCharsRegex = new Regex ( @"[^A-Za-z0-9._]" , RegexOptions . Compiled ) ;
828+ private static readonly Regex SplitCamelCaseRegex = new Regex ( "([A-Z]|[0-9]+)" , RegexOptions . Compiled ) ;
828829 private static readonly Regex HttpRegex = new Regex ( @"^http://" ,
829830 PclExport . Instance . RegexOptions | RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
830831
@@ -910,11 +911,11 @@ public static bool ContainsAny(this string text, params string[] testMatches)
910911 return false ;
911912 }
912913
913- public static string SafeVarName ( this string text )
914- {
915- if ( string . IsNullOrEmpty ( text ) ) return null ;
916- return InvalidVarCharsRegex . Replace ( text , "_" ) ;
917- }
914+ public static string SafeVarName ( this string text ) => ! string . IsNullOrEmpty ( text )
915+ ? InvalidVarCharsRegex . Replace ( text , "_" ) : null ;
916+
917+ public static string SafeVarRef ( this string text ) => ! string . IsNullOrEmpty ( text )
918+ ? InvalidVarRefCharsRegex . Replace ( text , "_" ) : null ;
918919
919920 public static string Join ( this List < string > items )
920921 {
0 commit comments