1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Reflection.Emit; 6 7 namespace System.Text.RegularExpressions 8 { 9 internal sealed class CompiledRegexRunnerFactory : RegexRunnerFactory 10 { 11 private readonly DynamicMethod _goMethod; 12 private readonly DynamicMethod _findFirstCharMethod; 13 private readonly DynamicMethod _initTrackCountMethod; 14 CompiledRegexRunnerFactory(DynamicMethod go, DynamicMethod firstChar, DynamicMethod trackCount)15 internal CompiledRegexRunnerFactory(DynamicMethod go, DynamicMethod firstChar, DynamicMethod trackCount) 16 { 17 _goMethod = go; 18 _findFirstCharMethod = firstChar; 19 _initTrackCountMethod = trackCount; 20 } 21 CreateInstance()22 protected internal override RegexRunner CreateInstance() 23 { 24 CompiledRegexRunner runner = new CompiledRegexRunner(); 25 runner.SetDelegates((Action<RegexRunner>)_goMethod.CreateDelegate(typeof(Action<RegexRunner>)), 26 (Func<RegexRunner, bool>)_findFirstCharMethod.CreateDelegate(typeof(Func<RegexRunner, bool>)), 27 (Action<RegexRunner>)_initTrackCountMethod.CreateDelegate(typeof(Action<RegexRunner>))); 28 29 return runner; 30 } 31 } 32 } 33