The Labs \ Source Viewer \ SSCLI \ System.Text.RegularExpressions \ CompiledRegexRunnerFactory

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CompiledRegexRunnerFactory.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System.Reflection.Emit;
  16. using System.Diagnostics;
  17. using System.Security.Permissions;
  18. namespace System.Text.RegularExpressions
  19. {
  20.    
  21.    
  22.     internal sealed class CompiledRegexRunnerFactory : RegexRunnerFactory
  23.     {
  24.         DynamicMethod goMethod;
  25.         DynamicMethod findFirstCharMethod;
  26.         DynamicMethod initTrackCountMethod;
  27.        
  28.         internal CompiledRegexRunnerFactory(DynamicMethod go, DynamicMethod firstChar, DynamicMethod trackCount)
  29.         {
  30.             this.goMethod = go;
  31.             this.findFirstCharMethod = firstChar;
  32.             this.initTrackCountMethod = trackCount;
  33.             //Debug.Assert(goMethod != null && findFirstCharMethod != null && initTrackCountMethod != null, "can't be null");
  34.         }
  35.        
  36.         protected internal override RegexRunner CreateInstance()
  37.         {
  38.             CompiledRegexRunner runner = new CompiledRegexRunner();
  39.            
  40.             new ReflectionPermission(PermissionState.Unrestricted).Assert();
  41.             runner.SetDelegates((NoParamDelegate)goMethod.CreateDelegate(typeof(NoParamDelegate)), (FindFirstCharDelegate)findFirstCharMethod.CreateDelegate(typeof(FindFirstCharDelegate)), (NoParamDelegate)initTrackCountMethod.CreateDelegate(typeof(NoParamDelegate)));
  42.            
  43.             return runner;
  44.         }
  45.     }
  46.    
  47.     internal delegate RegexRunner CreateInstanceDelegate();
  48. }

Developer Fusion