Initial commit
[mono.git] / mcs / class / referencesource / System / regex / system / text / regularexpressions / compiledregexrunnerfactory.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="CompiledRegexRunnerFactory.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 using System.Reflection.Emit;
8 using System.Diagnostics;
9 using System.Security.Permissions;
10
11 #if !SILVERLIGHT
12
13 namespace System.Text.RegularExpressions {
14
15     
16     internal sealed class CompiledRegexRunnerFactory : RegexRunnerFactory {
17         DynamicMethod goMethod;
18         DynamicMethod findFirstCharMethod;
19         DynamicMethod initTrackCountMethod;
20
21         internal CompiledRegexRunnerFactory (DynamicMethod go, DynamicMethod firstChar, DynamicMethod trackCount) {
22             this.goMethod = go;
23             this.findFirstCharMethod = firstChar;
24             this.initTrackCountMethod = trackCount;
25             //Debug.Assert(goMethod != null && findFirstCharMethod != null && initTrackCountMethod != null, "can't be null");
26         }
27         
28         protected internal override RegexRunner CreateInstance() {
29             CompiledRegexRunner runner = new CompiledRegexRunner();
30
31             new ReflectionPermission(PermissionState.Unrestricted).Assert();
32             runner.SetDelegates((NoParamDelegate)       goMethod.CreateDelegate(typeof(NoParamDelegate)),
33                                 (FindFirstCharDelegate) findFirstCharMethod.CreateDelegate(typeof(FindFirstCharDelegate)),
34                                 (NoParamDelegate)       initTrackCountMethod.CreateDelegate(typeof(NoParamDelegate)));
35
36             return runner;
37         }
38     }
39
40     internal delegate RegexRunner CreateInstanceDelegate();
41 }
42
43 #endif
44