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


C# ExpressionStatementSyntax.FirstAncestorOrSelf方法代码示例

本文整理汇总了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;
 }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:14,代码来源:DisposableVariableNotDisposedCodeFixProvider.cs

示例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;
        }
开发者ID:x335,项目名称:WootzJs,代码行数:40,代码来源:Idioms.cs


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