System.Text.RegularExpressions.RegexLWCGCompiler.FactoryInstanceFromCode C# (CSharp) 메소드

FactoryInstanceFromCode() 개인적인 메소드

private FactoryInstanceFromCode ( RegexCode code, RegexOptions options ) : RegexRunnerFactory
code RegexCode
options RegexOptions
리턴 RegexRunnerFactory
        internal RegexRunnerFactory FactoryInstanceFromCode(RegexCode code, RegexOptions options) {
            _code       = code;
            _codes      = code._codes;
            _strings    = code._strings;
            _fcPrefix   = code._fcPrefix;
            _bmPrefix   = code._bmPrefix;
            _anchors    = code._anchors;
            _trackcount = code._trackcount;
            _options    = options;
        
            // pick a unique number for the methods we generate
            int regexnum = Interlocked.Increment(ref _regexCount);
            string regexnumString = regexnum.ToString(CultureInfo.InvariantCulture);
            
            DynamicMethod goMethod = DefineDynamicMethod("Go" + regexnumString, null, typeof(CompiledRegexRunner));
            GenerateGo();
    
            DynamicMethod firstCharMethod = DefineDynamicMethod("FindFirstChar" + regexnumString, typeof(bool), typeof(CompiledRegexRunner));
            GenerateFindFirstChar();
    
            DynamicMethod trackCountMethod = DefineDynamicMethod("InitTrackCount" + regexnumString, null, typeof(CompiledRegexRunner));
            GenerateInitTrackCount();

            return new CompiledRegexRunnerFactory(goMethod, firstCharMethod, trackCountMethod);
        }
        

Usage Example

        /* 
         * Entry point to dynamically compile a regular expression.  The expression is compiled to 
         * an in memory assembly.
         */
        internal static RegexRunnerFactory Compile(RegexCode code, RegexOptions options) {
            RegexLWCGCompiler c = new RegexLWCGCompiler();
            RegexRunnerFactory factory;

            new ReflectionPermission(PermissionState.Unrestricted).Assert();
            try {
                factory = c.FactoryInstanceFromCode(code, options);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            return factory;
        }