public async Task <string> RunAsync() { var blocks = BlockFactory.Parse(Content); blocks.Insert(0, UsingBlock.Parse("@using System.Text;")); blocks.Insert(1, ScriptBlock.Parse("@{ var Out = new StringBuilder(); }")); blocks.Add(ScriptBlock.Parse("@{ string result = Out.ToString(); }")); var csharp = blocks.ToCSharp(); var options = ScriptOptions.Default; foreach (var refelence in References) { options = options.AddReferences(refelence); } var script = CSharpScript.Create(csharp, options); var state = await script.RunAsync(); foreach (var variable in state.Variables) { if (variable.Name == "result") { return(variable.Value.ToString()); } } return(string.Empty); }
public void Equality_Default() { var a = new UsingBlock(); var b = new UsingBlock(); Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
public void DefaultValues() { var sut = new UsingBlock(); Assert.AreEqual(new VariableReference(), sut.Reference); Assert.AreEqual(Lists.NewList <IStatement>(), sut.Body); Assert.AreNotEqual(0, sut.GetHashCode()); Assert.AreNotEqual(1, sut.GetHashCode()); }
protected override void ExecuteCore() { CodeUnit.EnsureUsingBlockExists(); UsingBlock usingSection = CodeUnit.UsingSection; foreach (UsingDirective dir in list) { Add(usingSection, dir); } }
public async Task <string> CompileToCSharpAsync() { var blocks = BlockFactory.Parse(Content); blocks.Insert(0, UsingBlock.Parse("@using System.Text;")); blocks.Insert(1, ScriptBlock.Parse("@{ var Out = new StringBuilder(); }")); blocks.Add(ScriptBlock.Parse("@{ string result = Out.ToString(); }")); return(await blocks.ToCSharpAsync()); }
public void Equality_DifferentBody() { var a = new UsingBlock(); a.Body.Add(new ContinueStatement()); var b = new UsingBlock(); b.Body.Add(new GotoStatement()); Assert.AreNotEqual(a, b); Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode()); }
public void Equality_DifferentReference() { var a = new UsingBlock { Reference = SomeVarRef("a") }; var b = new UsingBlock { Reference = SomeVarRef("b") }; Assert.AreNotEqual(a, b); Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode()); }
public void ChildrenIdentity() { var sut = new UsingBlock { Reference = SomeVarRef("a"), Body = { new ReturnStatement() } }; AssertChildren(sut, sut.Reference, sut.Body.First()); }
private void Add(UsingBlock usingSection, UsingDirective usingEntry) { if (usingSection.VMembers.Children.Count == 1 && usingSection.FirstUsing != null && usingSection.FirstUsing.Text == "") { usingSection.VMembers.Children.Replace(usingSection.FirstUsing, usingEntry); } else { usingSection.VMembers.Children.Add(usingEntry); } }
public void SettingValues() { var sut = new UsingBlock { Reference = SomeVarRef("a"), Body = { new ReturnStatement() } }; Assert.AreEqual(SomeVarRef("a"), sut.Reference); Assert.AreEqual(Lists.NewList(new ReturnStatement()), sut.Body); }
public void UsingBlock() { var sst = new UsingBlock { Reference = SSTUtil.VariableReference("variable"), Body = { new BreakStatement() } }; AssertPrint( sst, "using (variable)", "{", " break;", "}"); }
public void Equality_ReallyTheSame() { var a = new UsingBlock { Reference = SomeVarRef("b") }; a.Body.Add(new ReturnStatement()); var b = new UsingBlock { Reference = SomeVarRef("b") }; b.Body.Add(new ReturnStatement()); Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
static void Main(string[] args) { { UsingBlock block = new UsingBlock(); block.SayHello(); } { using UsingBlock block = new UsingBlock(); { block.SayHello(); } block.SayHello(); } using (UsingBlock block = new UsingBlock()) { block.SayHello(); } Console.ReadLine(); }
public override void VisitUsingStatement(IUsingStatement block, IList <IStatement> body) { AddIf(block, CompletionCase.EmptyCompletionBefore, body); var usingBlock = new UsingBlock(); IVariableReference varRef = new VariableReference(); // case 1: variable declarations if (block.VariableDeclarations.Any()) { var decl = block.VariableDeclarations[0]; decl.Accept(this, body); varRef = new VariableReference { Identifier = decl.DeclaredName }; } // case 2: expressions (var refs, method calls ...) else if (block.Expressions.Any()) { var expr = block.Expressions[0]; varRef = _exprVisitor.ToVariableRef(expr, body); } usingBlock.Reference = varRef; var bodyAsIBlock = block.Body as IBlock; if (bodyAsIBlock != null && !bodyAsIBlock.Statements.Any() && IsTargetMatch(block, CompletionCase.InBody)) { usingBlock.Body.Add(new ExpressionStatement { Expression = new CompletionExpression() }); } else { block.Body.Accept(this, usingBlock.Body); } body.Add(usingBlock); AddIf(block, CompletionCase.EmptyCompletionAfter, body); }
protected override void UnExecuteCore() { RootControl root = Root.MyRootControl; UsingBlock usingSection = CodeUnit.UsingSection; foreach (UsingDirective b in this.list) { if (root.IsFocusInsideControl(b.MyControl)) { b.RemoveFocus(); } usingSection.VMembers.Children.Delete(b); } if (usingSection.VMembers.Children.Count == 0) { if (root.IsFocusInsideControl(usingSection.MyControl)) { usingSection.RemoveFocus(); } CodeUnit.Children.Delete((Block)usingSection); } }
public void VisitorWithReturnIsImplemented() { var sut = new UsingBlock(); sut.Accept(23).VerifyWithReturn(v => v.Visit(sut, 23)); }
public virtual void Visit(UsingBlock block) { }
public override void Visit(UsingBlock block) { }
// within this using block make the DetachedMetadataStore == ms public static UsingBlock ShareWithDetached(MetadataStore ms) { return(UsingBlock.Create(MetadataStore.Detached, ms, (x) => MetadataStore.Detached = x)); }
public override void Visit(UsingBlock block) { foreach (UsingDirective dir in block.VMembers.Children) { WriteIndent(); Visit(dir); NewLine(); } }
/** * terminar de colocar os metodos dentro do case e começar a utilizar para * os novos métodos que seram criados. ver se a separação dos serviços podem ser melhorados * colocar maneira de voltar dos métodos para o menu principal e poder escolher * outro e continuar a testar. */ static void Main(string[] args) { var dataHora = new DataHora(); var geometria = new Geometria(); var enumera = new Enumeradores(); var contrato = new ContratoDeTrabalho(); var social = new SocialPosts(); var pedido = new Pedido(); var upDown = new UpDowncasting(); var sobre = new PalavrasVirtuais(); var sela = new MetodoSelado(); var pagaFun = new PagamentoFuncio(); var regisProduct = new RegisterProduct(); var abstraCla = new AbstrataClasse(); var abstraMetod = new AbstrataMetod(); var tax = new TaxService(); var teste = new Teste(); var tratando = new TratandoExcecoes(); var operation = new AccountOperations(); var file = new OperationFile(); var usingBlock = new UsingBlock(); Console.WriteLine($"Escolha o que vc deseja testar!!!"); Console.WriteLine($"1 - VerificaHora" + "\r\n2 - CalculoTriangulo" + "\r\n3 - PropriedadesDateTime" + "\r\n4 - PropriedadesTimeSpan" + "\r\n5 - DatetimeKindIso8601" + "\r\n6 - Enumeradores" + "\r\n7 = Contrato de Trabalho" + "\r\n8 - Posts" + "\r\n9 - PedidoCompra" + "\r\n10 - Herança" + "\r\n11 - Upcasting Downcasting" + "\r\n12 - Sobreposição, palavras virtuais" + "\r\n13 - Classe/Metodo Selada" + "\r\n14 - Pagamento Funcionário" + "\r\n15 - Register Product" + "\r\n16 - Abstrata Classe" + "\r\n17 - Abstrato Metodo" + "\r\n18 - Imposto" + "\r\n19 - teste" + "\r\n20 - TryCatch" + "\r\n21 - Exception personalizada" + "\r\n22 - Desafio Exception" + "\r\n23 - Matrizes com listas" + "\r\n24 - File" + "\r\n25 - FileStream" + "\r\n26 - Using block" + "\r\n27 - Stream writer"); int escolha = int.Parse(Console.ReadLine()); switch (escolha) { case 1: dataHora.VerificaHora(); break; case 2: geometria.CalculoTriangulo(); break; case 3: dataHora.PropriedadesDateTime(); break; case 4: dataHora.PropriedadesTimeSpan(); break; case 5: dataHora.DateTimeKindIso8601(); break; case 6: enumera.Pedido(); break; case 7: contrato.AddWorker(); break; case 8: social.SocialMidia(); break; case 9: pedido.PedidoCompra(); break; case 11: upDown.UpDown(); break; case 12: sobre.SobreposicaoPalavras(); break; case 13: sela.ClasseSeladaM(); break; case 14: pagaFun.PagamentoFunc(); break; case 15: regisProduct.RegisterProd(); break; case 16: abstraCla.AbstrataCla(); break; case 17: abstraMetod.MetodExemplo(); break; case 18: tax.CalculoImpostoHaPagar(); break; case 19: teste.Teste1(); break; case 20: tratando.tratandoException(); break; case 21: tratando.ExceptionPersonalized(); break; case 22: operation.Operations(); break; case 23: teste.MatrizComLista(); break; case 24: file.OpeFile(); break; case 25: file.OpeFileStream(); break; case 26: usingBlock.OpeUsingBlock(); break; case 27: file.OpeFileStreamWrite(); break; default: Console.WriteLine($"Não temos esta opção tente novamente!!!"); break; } //VerificaHora(); //Calculo do triangulo //CalculoTriangulo(); //mostrando informação da pessoal //MostraPessoa(); //mostrando os funcionarios //MostraFuncionario(); // EstoqueProdutos(); //CalculoRetangulo(); //NotasAluno(); //CalculandoCircunferencia(); //ConverteMoeda(); //EstoqueProdutosEncapsulamento(); //fazer transferencias de bancos //MovimentacoesBancarias(); //AlugandoQuartos(); //UsandoListas(); //AumentoDeSalario(); //Matrizes(); //exercicio M linhas e N colunas //DesafioMatrizes(); //funções string //FuncoesString(); //funções datetime //FuncoesDateTime(); //TimeSpan //funcoesTimeSpan(); }