public void VariableFromMethodCall() { CompleteInClass(@" public StreamWriter M() { return new StreamWriter(""file.txt""); } public void N() { using (M()) { $ return; } }"); AssertBody( "N", VarDecl("$0", _streamWriter), Assign("$0", Invoke("this", Fix.Method(_streamWriter, Type("C"), "M"))), new UsingBlock { Reference = VarRef("$0"), Body = { Fix.EmptyCompletion, new ReturnStatement { IsVoid = true } } }); }
public void IndexAccessOnMethodResult() { CompleteInClass(@" public int[] GetArray() { return new int[10]; } public void M() { int i = this.GetArray()[1]; $ }"); AssertBody( "M", VarDecl("i", Fix.Int), VarDecl("$0", Fix.IntArray), Assign("$0", Invoke("this", Fix.Method(Fix.IntArray, Type("C"), "GetArray"))), Assign( "i", new IndexAccessExpression { Reference = VarRef("$0"), Indices = { Const("1") } }), Fix.EmptyCompletion); }
public void CastingMethodResult() { CompleteInClass(@" public int GetInt() { return 1; } public void M() { var i = (float)GetInt(); $ }"); AssertBody( "M", VarDecl("i", Fix.Float), VarDecl("$0", Fix.Int), Assign("$0", Invoke("this", Fix.Method(Fix.Int, Type("C"), "GetInt"))), Assign("i", new CastExpression { TargetType = Fix.Float, Reference = VarRef("$0") }), Fix.EmptyCompletion); }
public void CallingMethodWithProperty() { CompleteInClass(@" public string Name { get; set; } public void M() { N(this.Name); } public void N(string s) { s.$ }"); var nMethod = Fix.Method(Fix.Void, Type("C"), "N", Fix.Parameter(Fix.String, "s")); var namePropertyRef = PropertyRef(Fix.Property(Fix.String, Type("C"), "Name"), VarRef("this")); AssertBody( "M", ExprStmt(Invoke("this", nMethod, RefExpr(namePropertyRef)))); }