本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax.FirstAncestorOrSelf方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatementSyntax.FirstAncestorOrSelf方法的具体用法?C# ExpressionStatementSyntax.FirstAncestorOrSelf怎么用?C# ExpressionStatementSyntax.FirstAncestorOrSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax
的用法示例。
在下文中一共展示了ExpressionStatementSyntax.FirstAncestorOrSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRootAddingDisposeToEndOfMethod
private static SyntaxNode CreateRootAddingDisposeToEndOfMethod(SyntaxNode root, ExpressionStatementSyntax statement, ILocalSymbol identitySymbol)
{
var method = statement.FirstAncestorOrSelf<MethodDeclarationSyntax>();
var newDispose = ImplementsDisposableExplicitly(identitySymbol.Type)
? SyntaxFactory.ExpressionStatement(SyntaxFactory.InvocationExpression(
SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
SyntaxFactory.ParenthesizedExpression(SyntaxFactory.CastExpression(SyntaxFactory.ParseName("System.IDisposable").WithAdditionalAnnotations(Simplifier.Annotation), SyntaxFactory.IdentifierName(identitySymbol.Name))),
SyntaxFactory.IdentifierName("Dispose"))))
: SyntaxFactory.ParseStatement($"{identitySymbol.Name}.Dispose();");
newDispose = newDispose.WithAdditionalAnnotations(Formatter.Annotation);
var last = method.Body.Statements.Last();
var newRoot = root.InsertNodesAfter(method.Body.Statements.Last(), new[] { newDispose });
return newRoot;
}
示例2: TryUnwrapJsniStatement
public bool TryUnwrapJsniStatement(ExpressionStatementSyntax statement, out JsStatement result)
{
var expression = statement.Expression;
if (expression is InvocationExpressionSyntax)
{
var jsniInvocation = (InvocationExpressionSyntax)expression;
var symbolInfo = Context.Instance.Compilation.GetSemanticModel(expression.SyntaxTree).GetSymbolInfo(jsniInvocation);
var method = (IMethodSymbol)symbolInfo.Symbol;
var arguments = jsniInvocation.ArgumentList.Arguments.Select(x => (JsExpression)x.Accept(transformer)).ToArray();
if (symbolInfo.Symbol == null)
{
var classText = statement.FirstAncestorOrSelf<ClassDeclarationSyntax>().NormalizeWhitespace().ToString();
var diagnostics = transformer.model.GetDiagnostics().Select(x => x.ToString()).ToArray();
}
if (method.ReducedFrom != null && !method.ReducedFrom.Equals(method))
{
method = method.ReducedFrom;
var target = (JsExpression)jsniInvocation.Expression.Accept(transformer);
var methodTarget = target is JsMemberReferenceExpression ? ((JsMemberReferenceExpression)target).Target : target;
arguments = new[] { methodTarget }.Concat(arguments).ToArray();
}
if (method != null && Equals(method.ContainingType, Context.Instance.JsniType))
{
switch (method.Name)
{
case "forin":
var target = arguments[0];
var invocation = (JsInvocationExpression)arguments[1];
var function = (JsFunction)invocation.Arguments[1];
result = Js.ForIn(function.Parameters[0].Name, target).Body(function.Body);
return true;
}
}
}
result = null;
return false;
}