当前位置: 首页>>代码示例>>C#>>正文


C# ReturnStatement类代码示例

本文整理汇总了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;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:30,代码来源:OverrideToStringMethodDialog.xaml.cs

示例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);
            });
        }
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:27,代码来源:ScriptTests.cs

示例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());
        }
开发者ID:DaveVdE,项目名称:adamjsgenerator,代码行数:11,代码来源:ReturnStatementTests.cs

示例4: PostWalk

 protected internal virtual void PostWalk(ReturnStatement node) { }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:1,代码来源:Walker.Generated.cs

示例5: Walk

 // ReturnStatement
 protected internal virtual bool Walk(ReturnStatement node) { return true; }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:2,代码来源:Walker.Generated.cs

示例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;
			}
开发者ID:pgoron,项目名称:monodevelop,代码行数:14,代码来源:CSharpParser.cs

示例7: VisitReturnStatement

		public void VisitReturnStatement(ReturnStatement returnStatement)
		{
			StartNode(returnStatement);
			WriteKeyword(ReturnStatement.ReturnKeywordRole);
			if (!returnStatement.Expression.IsNull) {
				Space();
				returnStatement.Expression.AcceptVisitor(this);
			}
			Semicolon();
			EndNode(returnStatement);
		}
开发者ID:x-strong,项目名称:ILSpy,代码行数:11,代码来源:CSharpOutputVisitor.cs

示例8: Visit

 public virtual void Visit(ReturnStatement expression)
 {
     if (expression.Expression != null)
     {
         outStream.Write("return ");
         expression.Expression.Accept(this);
     }
     else
         outStream.Write("return");
 }
开发者ID:reshadi2,项目名称:mcjs,代码行数:10,代码来源:AstWriter.cs

示例9: VisitReturnStatement

		public virtual void VisitReturnStatement (ReturnStatement returnStatement)
		{
			VisitChildren (returnStatement);
		}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:4,代码来源:DepthFirstAstVisitor.cs

示例10: Exit

 public virtual void Exit(ReturnStatement node)
 {
 }
开发者ID:buunguyen,项目名称:bike,代码行数:3,代码来源:EnterForWalkerGenerator.cs

示例11: Walk

 // ReturnStatement
 public virtual bool Walk(ReturnStatement node) { return true; }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:2,代码来源:PythonWalker.Generated.cs

示例12: VisitReturn

 public void VisitReturn(ReturnStatement r)
 {
     if (r.Expression != null)
         gen.Return(r.Expression.Accept(xlat));
     else
         gen.Return();
 }
开发者ID:uxmal,项目名称:pytocs,代码行数:7,代码来源:StatementTranslator.cs

示例13: Enter

 public virtual bool Enter(ReturnStatement node)
 {
     return true;
 }
开发者ID:buunguyen,项目名称:bike,代码行数:4,代码来源:EnterForWalkerGenerator.cs

示例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();
        }
开发者ID:velus,项目名称:Async-Sim-Testing,代码行数:37,代码来源:CSCodeGenerator.cs


注:本文中的ReturnStatement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。