private Injector demoExtensions() { return(new DelegateInjector(compiler => { Asynch.Apply(compiler); Match.Apply(compiler); Contract.Apply(compiler); })); }
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 }