11// Copyright © https://myCSharp.de - all rights reserved
22
3+ using System . Collections . Frozen ;
34using System . Text . RegularExpressions ;
45
56namespace MyCSharp . HttpUserAgentParser ;
@@ -121,8 +122,8 @@ internal static readonly (string Token, string Name, HttpUserAgentPlatformType P
121122 ] ;
122123
123124 // Precompiled platform regex map to attach to PlatformInformation without per-call allocations
124- private static readonly Dictionary < string , Regex > s_platformRegexMap = s_platformRules
125- . ToDictionary ( p => p . Token , p => CreateDefaultPlatformRegex ( p . Token ) , StringComparer . OrdinalIgnoreCase ) ;
125+ private static readonly FrozenDictionary < string , Regex > s_platformRegexMap = s_platformRules
126+ . ToFrozenDictionary ( p => p . Token , p => CreateDefaultPlatformRegex ( p . Token ) , StringComparer . OrdinalIgnoreCase ) ;
126127
127128 internal static Regex GetPlatformRegexForToken ( string token ) => s_platformRegexMap [ token ] ;
128129
@@ -139,7 +140,7 @@ private static Regex CreateDefaultBrowserRegex(string key)
139140 /// <summary>
140141 /// Browsers
141142 /// </summary>
142- public static readonly Dictionary < Regex , string > Browsers = new ( )
143+ public static readonly FrozenDictionary < Regex , string > Browsers = new Dictionary < Regex , string > ( )
143144 {
144145 { CreateDefaultBrowserRegex ( "OPR" ) , "Opera" } ,
145146 { CreateDefaultBrowserRegex ( "Flock" ) , "Flock" } ,
@@ -176,7 +177,7 @@ private static Regex CreateDefaultBrowserRegex(string key)
176177 { CreateDefaultBrowserRegex ( "Maxthon" ) , "Maxthon" } ,
177178 { CreateDefaultBrowserRegex ( "ipod touch" ) , "Apple iPod" } ,
178179 { CreateDefaultBrowserRegex ( "Ubuntu" ) , "Ubuntu Web Browser" } ,
179- } ;
180+ } . ToFrozenDictionary ( ) ;
180181
181182 /// <summary>
182183 /// Fast-path browser token rules. If these fail to extract a version, code will fall back to regex rules.
@@ -223,7 +224,7 @@ internal static readonly (string Name, string DetectToken, string? VersionToken)
223224 /// <summary>
224225 /// Mobiles
225226 /// </summary>
226- public static readonly Dictionary < string , string > Mobiles = new ( StringComparer . InvariantCultureIgnoreCase )
227+ public static readonly FrozenDictionary < string , string > Mobiles = new Dictionary < string , string > ( StringComparer . InvariantCultureIgnoreCase )
227228 {
228229 // Legacy
229230 { "mobileexplorer" , "Mobile Explorer" } ,
@@ -306,7 +307,7 @@ internal static readonly (string Name, string DetectToken, string? VersionToken)
306307 { "up.browser" , "Generic Mobile" } ,
307308 { "smartphone" , "Generic Mobile" } ,
308309 { "cellphone" , "Generic Mobile" } ,
309- } ;
310+ } . ToFrozenDictionary ( StringComparer . OrdinalIgnoreCase ) ;
310311
311312 /// <summary>
312313 /// Robots
@@ -385,8 +386,9 @@ public static readonly (string Key, string Value)[] Robots =
385386 /// <summary>
386387 /// Tools
387388 /// </summary>
388- public static readonly Dictionary < string , string > Tools = new ( StringComparer . OrdinalIgnoreCase )
389+ public static readonly FrozenDictionary < string , string > Tools = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase )
389390 {
390391 { "curl" , "curl" }
391- } ;
392+ }
393+ . ToFrozenDictionary ( StringComparer . OrdinalIgnoreCase ) ;
392394}
0 commit comments