本文整理汇总了C#中ReturnStatement类的典型用法代码示例。如果您正苦于以下问题:C# ReturnStatement类的具体用法?C# ReturnStatement怎么用?C# ReturnStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReturnStatement类属于命名空间,在下文中一共展示了ReturnStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCode
protected override string GenerateCode(ITypeDefinition currentClass)
{
// string[] fields = listBox.SelectedItems.OfType<PropertyOrFieldWrapper>().Select(f2 => f2.MemberName).ToArray();
string[] fields = parameterList.Where(f => f.IsIncluded).Select(f2 => f2.MemberName).ToArray();
PrimitiveExpression formatString = new PrimitiveExpression(GenerateFormatString(currentClass, editor.Language.CodeGenerator, fields));
List<Expression> param = new List<Expression>() { formatString };
ReturnStatement ret = new ReturnStatement(new InvocationExpression(
new MemberReferenceExpression(new TypeReferenceExpression(ConvertType(KnownTypeCode.String)), "Format"),
param.Concat(fields.Select(f => new IdentifierExpression(f))).ToList()
));
if (baseCallNode != null) {
MethodDeclaration insertedOverrideMethod = refactoringContext.GetNode().PrevSibling as MethodDeclaration;
if (insertedOverrideMethod == null) {
// We are not inside of a method declaration
return null;
}
using (Script script = refactoringContext.StartScript()) {
NewLineNode nextNewLineNode = insertedOverrideMethod.NextSibling as NewLineNode;
// Find base method call and replace it by return statement
script.AddTo(insertedOverrideMethod.Body, ret);
AppendNewLine(script, insertedOverrideMethod, nextNewLineNode);
}
}
return null;
}
示例2: InsertAfterStatementIndentsLikeStatement
public void InsertAfterStatementIndentsLikeStatement()
{
var input [email protected]"
public class Test
{
void DoublyIndented()
{
System.Console.WriteLine(""hello"");
}
}";
var expected = @"
public class Test
{
void DoublyIndented()
{
System.Console.WriteLine(""hello"");
return;
}
}";
DoInsertAfterTest(input, expected, (syntaxTree, script) =>
{
var nodeToInsert = new ReturnStatement();
var nodeToInsertAfter = syntaxTree.DescendantsAndSelf.OfType<ExpressionStatement>().Single();
script.InsertAfter(nodeToInsertAfter,nodeToInsert);
});
}
示例3: ReturnStatementProducesReturnWithValue
public void ReturnStatementProducesReturnWithValue()
{
var statement = new ReturnStatement(3);
Assert.AreEqual(3, statement.Value);
Assert.AreEqual("return 3;", statement.ToString());
statement.Value = "Yes!";
Assert.AreEqual("return \"Yes!\";", statement.ToString());
}
示例4: PostWalk
protected internal virtual void PostWalk(ReturnStatement node) { }
示例5: Walk
// ReturnStatement
protected internal virtual bool Walk(ReturnStatement node) { return true; }
示例6: Visit
public override object Visit (Return returnStatement)
{
var result = new ReturnStatement ();
result.AddChild (new CSharpTokenNode (Convert (returnStatement.loc), "return".Length), ReturnStatement.Roles.Keyword);
if (returnStatement.Expr != null)
result.AddChild ((INode)returnStatement.Expr.Accept (this), ReturnStatement.Roles.Expression);
var location = LocationsBag.GetLocations (returnStatement);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ReturnStatement.Roles.Semicolon);
return result;
}
示例7: VisitReturnStatement
public void VisitReturnStatement(ReturnStatement returnStatement)
{
StartNode(returnStatement);
WriteKeyword(ReturnStatement.ReturnKeywordRole);
if (!returnStatement.Expression.IsNull) {
Space();
returnStatement.Expression.AcceptVisitor(this);
}
Semicolon();
EndNode(returnStatement);
}
示例8: Visit
public virtual void Visit(ReturnStatement expression)
{
if (expression.Expression != null)
{
outStream.Write("return ");
expression.Expression.Accept(this);
}
else
outStream.Write("return");
}
示例9: VisitReturnStatement
public virtual void VisitReturnStatement (ReturnStatement returnStatement)
{
VisitChildren (returnStatement);
}
示例10: Exit
public virtual void Exit(ReturnStatement node)
{
}
示例11: Walk
// ReturnStatement
public virtual bool Walk(ReturnStatement node) { return true; }
示例12: VisitReturn
public void VisitReturn(ReturnStatement r)
{
if (r.Expression != null)
gen.Return(r.Expression.Accept(xlat));
else
gen.Return();
}
示例13: Enter
public virtual bool Enter(ReturnStatement node)
{
return true;
}
示例14: VisitReturnStatement
public override void VisitReturnStatement(ReturnStatement returnStatement)
{
if (!returnStatement.Expression.IsNull) {
AddIssue(
returnStatement,
string.Format (ctx.TranslateString("`{0}': A return keyword must not be followed by any expression when method returns void"), currentMethodName),
new CodeAction (
ctx.TranslateString("Remove returned expression"),
script => {
script.Remove(returnStatement.Expression);
}
)
);
}
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:15,代码来源:CS0127ReturnMustNotBeFollowedByAnyExpression.cs
示例15: GenerateReturnStatement
/// <summary>
/// Generates the code for a ReturnStatement node.
/// </summary>
/// <param name="rs">The ReturnStatement node.</param>
/// <returns>String containing C# code for ReturnStatement rs.</returns>
private string GenerateReturnStatement(ReturnStatement rs)
{
StringBuilder retVal = new StringBuilder();
bool dump = FuncCallsMarc();
if (IsParentEnumerable)
{
retVal.Append(GenerateLine("{ "));
if (rs.kids.Count == 0)
retVal.Append(GenerateLine("yield break;", rs));
else
{
retVal.Append(Generate(string.Format("yield return ({0})(", _currentGlobalFunctionDeclaration.ReturnType), rs));
foreach (SYMBOL kid in rs.kids)
retVal.Append(GenerateNode(kid));
retVal.Append(GenerateLine(");", null));
retVal.Append(GenerateLine("yield break;", null));
}
retVal.Append(GenerateLine("}"));
}
else
{
retVal.Append(Generate(string.Format("return ({0})", _currentGlobalFunctionDeclaration.ReturnType), rs));
foreach (SYMBOL kid in rs.kids)
retVal.Append(GenerateNode(kid));
}
if (dump)
return DumpFunc(dump) + retVal.ToString() + DumpAfterFunc(dump);
return retVal.ToString();
}