コード例 #1
0
ファイル: TranslationService.cs プロジェクト: zihotki/Excess
 private Injector demoExtensions()
 {
     return(new DelegateInjector(compiler =>
     {
         Asynch.Apply(compiler);
         Match.Apply(compiler);
         Contract.Apply(compiler);
     }));
 }
コード例 #2
0
ファイル: ExtUsage.cs プロジェクト: zihotki/Excess
        public void AsynchUsage()
        {
            RoslynCompiler compiler = new RoslynCompiler();

            Asynch.Apply(compiler);

            SyntaxTree tree = null;
            string     text = null;

            //event handler usage
            var AsynchText = @"
                class foo
                {
                    void bar()
                    {
                        asynch()
                        {
                            foobar();
                        }
                    }
                }";

            tree = compiler.ApplySemanticalPass(AsynchText, out text);
            Assert.IsTrue(tree.GetRoot()
                          .DescendantNodes()
                          .OfType <ParenthesizedLambdaExpressionSyntax>()
                          .Count() == 1); //must have added a callback

            Assert.IsTrue(tree.GetRoot()
                          .DescendantNodes()
                          .OfType <InvocationExpressionSyntax>()
                          .Where(invocation => invocation.Expression.ToString() == "Task.Factory.StartNew")
                          .Count() == 1); //must have added a task factory invocation

            Assert.IsTrue(tree.GetRoot()
                          .DescendantNodes()
                          .OfType <LocalDeclarationStatementSyntax>()
                          .Count() == 1); //must have added a local variable for the asynch context

            var Synch = @"
                class foo
                {
                    void bar()
                    {
                        asynch()
                        {
                            foobar();
                            synch()
                            {
                                barfoo();
                            }
                        }
                    }
                }";

            tree = compiler.ApplySemanticalPass(Synch, out text);
            Assert.IsTrue(tree.GetRoot()
                          .DescendantNodes()
                          .OfType <ParenthesizedLambdaExpressionSyntax>()
                          .Count() == 2); //must have added a callback for asynch and another for synch
        }