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


C# BlockSyntax.AddStatements方法代码示例

本文整理汇总了C#中BlockSyntax.AddStatements方法的典型用法代码示例。如果您正苦于以下问题:C# BlockSyntax.AddStatements方法的具体用法?C# BlockSyntax.AddStatements怎么用?C# BlockSyntax.AddStatements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockSyntax的用法示例。


在下文中一共展示了BlockSyntax.AddStatements方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitBlock

 public override SyntaxNode VisitBlock(BlockSyntax node)
 {
     if (_applicationStart)
     {
         _applicationStart = false;
         if (_notPartialClass)
         {
             using (var globalModelSR = new StreamReader(_globalAsaxCsModelPath))
             {
                 _globalModel = globalModelSR.ReadToEnd();
             }
             _globalModelCompilationUnit = SyntaxFactory.ParseCompilationUnit(_globalModel);
             var globalModelNamespace = _globalModelCompilationUnit.ChildNodes().OfType<NamespaceDeclarationSyntax>().First();
             var globalModelClass = globalModelNamespace.ChildNodes().OfType<ClassDeclarationSyntax>().First();
             var globalModelApplicationStart = globalModelClass.ChildNodes().OfType<MethodDeclarationSyntax>().First(m => m.Identifier.ValueText == "Application_Start");
             var globalModelApplicationStartBody = globalModelApplicationStart.Body;
             node = node.AddStatements(globalModelApplicationStartBody.Statements.ToArray());
         }
         return node.AddStatements(SyntaxFactory.ParseStatement("Global." + _edmxName + "ApplicationStart(unityContainer);"));
     }
     return base.VisitBlock(node);
 }
开发者ID:bnjMichel,项目名称:waqs,代码行数:22,代码来源:ApplicationStartRewriter.cs

示例2: UnityInitializationMethodImplementationProvider

		public UnityInitializationMethodImplementationProvider(IEnumerable<IInitializationExpression> expressions)
		{
			Block = SyntaxFactory.Block();

#if DEBUG || DEBUGBUILD
			if (expressions == null)
				throw new ArgumentNullException(nameof(expressions), "Expressions collection cannot be null in " + typeof(UnityInitializationMethodImplementationProvider) + " as it is required to build the init method.");
#endif

			//Add each expression as a statement to the block
			//WARNING: Do not use foreach. At least not with WithStatements. It'll override the previous Block staterments each time.
			Block = Block.AddStatements(expressions.Select(x => x.Statement).ToArray());

			/*//foreach serialized field in the MonoBehaviour we take a look at it, add a statement for setting it via reflection
			//find an adapter for the source to dest Type and create an instance of it to initialize the EngineScriptComponent
			foreach(InitializationExpressionData data in expressions)
			{
				string fasterFlectMethodName = data.DestinationMemberType == System.Reflection.MemberTypes.Field ?
					@"SetFieldValue" : @"SetPropertyValue"; //can't use nameof with extension method I think. Will

				//genertaed using: http://roslynquoter.azurewebsites.net/ do not attempt to read. Ask Andrew
				Block = Block.WithStatements(SyntaxFactory.SingletonList<StatementSyntax>(SyntaxFactory.ExpressionStatement(
								SyntaxFactory.InvocationExpression(
									SyntaxFactory.MemberAccessExpression(
										SyntaxKind.SimpleMemberAccessExpression,
										SyntaxFactory.IdentifierName(
											targetEngineComponentFieldName),
										SyntaxFactory.IdentifierName(
											fasterFlectMethodName)) //method to call. We're using fasterflect cached reflection
									.WithOperatorToken(
										SyntaxFactory.Token(
											SyntaxKind.DotToken)))
								.WithArgumentList(
									SyntaxFactory.ArgumentList(
										SyntaxFactory.SeparatedList<ArgumentSyntax>(
											new SyntaxNodeOrToken[]{
												SyntaxFactory.Argument(
													SyntaxFactory.IdentifierName(
														data.DestinationFieldName)), //changed to destination field name
												SyntaxFactory.Token(
													SyntaxKind.CommaToken),
												SyntaxFactory.Argument(
													SyntaxFactory.ObjectCreationExpression(
														SyntaxFactory.IdentifierName(
															data.AdapterData.AdapterType.FullName)) //changed to create a new adapter type
													.WithNewKeyword(
														SyntaxFactory.Token(
															SyntaxKind.NewKeyword))
													.WithArgumentList(
														SyntaxFactory.ArgumentList(
															SyntaxFactory.SingletonSeparatedList<ArgumentSyntax>(
																SyntaxFactory.Argument(
																	SyntaxFactory.IdentifierName(
																		data.SourceFieldName)))) //changed to be the source field name
														.WithOpenParenToken(
															SyntaxFactory.Token(
																SyntaxKind.OpenParenToken))
														.WithCloseParenToken(
															SyntaxFactory.Token(
																SyntaxKind.CloseParenToken))))}))
									.WithOpenParenToken(
										SyntaxFactory.Token(
											SyntaxKind.OpenParenToken))
									.WithCloseParenToken(
										SyntaxFactory.Token(
											SyntaxKind.CloseParenToken))))));
											*/
		}
开发者ID:HelloKitty,项目名称:Testity,代码行数:68,代码来源:UnityInitializationMethodImplementationProvider.cs

示例3: ImplementConstructorBody

            private SyntaxNode ImplementConstructorBody(BlockSyntax declaration,
                                                                                 string sourcename,
                                                                                 ITypeSymbol targetTypeInfo,
                                                                                 ITypeSymbol sourceType)
            {
                var missingprops = GetMissingProperties(declaration, targetTypeInfo);

                var newproperties =
                    sourceType.GetMembers().Where(x => x.Kind == SymbolKind.Property).Cast<IPropertySymbol>().Where(x => x.IsMissing(missingprops));
                var newExpression = declaration.AddStatements(
                    newproperties.Select(x =>
                                             SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
                                                                                SyntaxFactory.IdentifierName(x.Name),
                                                                                SyntaxFactory.MemberAccessExpression(
                                                                                    SyntaxKind.SimpleMemberAccessExpression,
                                                                                    SyntaxFactory.IdentifierName(sourcename),
                                                                                    SyntaxFactory.IdentifierName(x.Name))))
                        .Cast<ExpressionSyntax>().Select(SyntaxFactory.ExpressionStatement).ToArray<StatementSyntax>());
                return newExpression;
            }
开发者ID:jarlrasm,项目名称:PhilTheCartographer,代码行数:20,代码来源:FillConstrutorBodyRefactoring.cs

示例4: AddStatement

 private static BlockSyntax AddStatement(BlockSyntax statementBlock, string statement)
 {
     return statementBlock.AddStatements(SF.ParseStatement(statement + "\n"));
 }
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:4,代码来源:SwmrGrainsGenerator.cs


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