List<Feature>Remove(f => f.Type == FeatureType.Bug); RSS 2.0
# Monday, May 04, 2009

Da in der Firma, für die ich arbeite, sehr viele Regular Expressions verwendet werden und wir auch sehr viele mit der Option “Compiled” versehen, ist es interessant zu wissen wie viele Regex denn gecached sind. Leider habe ich keine Möglichkeit gefunden, die Anzahl ohne Reflection zu ermitteln. Über diesen weg sollte es jedoch ziemlich performant sein:

   1: public static class RegexHelper
   2: {
   3:     private static ICollection _listFieldInfo;
   4:     private static readonly object _lockObject = new object();
   5:  
   6:     public static int GetCachedRegexCount()
   7:     {
   8:         if (_listFieldInfo == null)
   9:         {
  10:             lock (_lockObject)
  11:             {
  12:                 if (_listFieldInfo == null)
  13:                 {
  14:                     _listFieldInfo = (ICollection)typeof(Regex).GetField("livecode", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
  15:                 }
  16:             }
  17:         }
  18:  
  19:         return _listFieldInfo.Count;
  20:     }
  21: }

 

Ist ganz nützlich, wenn man prüfen will ob die gewählte Cachsize sinnvoll ist.

Monday, May 04, 2009 12:55:23 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0] -
Regex
Navigation
Categories
Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Jens Hofmann
Sign In
Statistics
Total Posts: 6
This Year: 0
This Month: 0
This Week: 0
Comments: 0
Themes
Pick a theme:
All Content © 2012, Jens Hofmann
DasBlog theme 'Business' created by Christoph De Baene (delarou)