コード例 #1
0
        private static void GetRuleInstance(Grammar grammar, string rule, string method, out MethodInfo onParse, out Grammar ruleInstance)
        {
            Type     type     = grammar.GetType();
            Assembly assembly = type.Assembly;
            Type     type2    = (rule == type.Name) ? type : GetTypeForRule(assembly, rule);

            if (type2 == null || !type2.IsSubclassOf(typeof(Grammar)))
            {
                throw new FormatException(SR.Get(SRID.RecognizerInvalidBinaryGrammar));
            }
            ruleInstance = ((type2 == type) ? grammar : ((Grammar)assembly.CreateInstance(type2.FullName)));
            onParse      = ruleInstance.MethodInfo(method);
        }
コード例 #2
0
        private static object TryExecuteOnRecognition(Grammar grammar, RecognitionResult result, string rootRule)
        {
            object result2 = result.Semantics.Value;

            if (grammar != null && grammar._scripts != null)
            {
                ScriptRef[] scripts = grammar._scripts;
                foreach (ScriptRef scriptRef in scripts)
                {
                    if (!(rootRule == scriptRef._rule) || scriptRef._method != RuleMethodScript.onRecognition)
                    {
                        continue;
                    }
                    object[] parameters = new object[1]
                    {
                        result
                    };
                    if (grammar._proxy != null)
                    {
                        Exception exceptionThrown;
                        result2 = grammar._proxy.OnRecognition(scriptRef._sMethod, parameters, out exceptionThrown);
                        if (exceptionThrown != null)
                        {
                            throw exceptionThrown;
                        }
                    }
                    else
                    {
                        Type       type   = grammar.GetType();
                        MethodInfo method = type.GetMethod(scriptRef._sMethod, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        result2 = method.Invoke(grammar, parameters);
                    }
                }
            }
            return(result2);
        }