CompileToDynamicMethod() public method

Compiles a plural rule abstract syntax tree into managed dynamic method delegate using an IL code generator.
public CompileToDynamicMethod ( Token astRoot, Type outputDelegateType ) : Delegate
astRoot NGettext.Plural.Ast.Token abstract syntax tree root node.
outputDelegateType System.Type Type of output delegate.
return System.Delegate
Esempio n. 1
0
        public void CompileCompleteRulesTest()
        {
            var parser = new AstTokenParser();
            var compiler = new PluralRuleCompiler();
            foreach (object[] mapping in GetParseCompleteRulesTestData())
            {
                var astRoot = parser.Parse((string)mapping[0]);
                var expectedSeq = (string)mapping[1];
                var dynamicMethod = (PluralRuleEvaluatorDelegate)compiler.CompileToDynamicMethod(astRoot, typeof(PluralRuleEvaluatorDelegate));

                for (int i = 0; i < 200; i++)
                {
                    var expected = int.Parse(expectedSeq[i].ToString());
                    Assert.Equal(expected, dynamicMethod(i));
                }
            }
        }
Esempio n. 2
0
        public void CompileRulesTest()
        {
            var parser = new AstTokenParser();
            var compiler = new PluralRuleCompiler();
            foreach (object[] mapping in GetParseRulesTestData())
            {
                var astRoot = parser.Parse((string)mapping[1]);
                var dynamicMethod = (PluralRuleEvaluatorDelegate)compiler.CompileToDynamicMethod(astRoot, typeof(PluralRuleEvaluatorDelegate));

                Assert.Equal((int)mapping[2], dynamicMethod(0));
            }
        }