本文整理汇总了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);
}
示例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))))));
*/
}
示例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;
}
示例4: AddStatement
private static BlockSyntax AddStatement(BlockSyntax statementBlock, string statement)
{
return statementBlock.AddStatements(SF.ParseStatement(statement + "\n"));
}