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


C# ExpressionSyntax.WithoutTrailingTrivia方法代码示例

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


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

示例1: IntroduceLocalAsync

		protected override Task<Document> IntroduceLocalAsync(
			SemanticDocument document,
			ExpressionSyntax expression,
			bool allOccurrences,
			bool isConstant,
			CancellationToken cancellationToken)
		{
			var options = document.Project.Solution.Workspace.Options;

			var newLocalNameToken = (SyntaxToken)GenerateUniqueLocalName(document, expression, isConstant, cancellationToken);
			var newLocalName = SyntaxFactory.IdentifierName(newLocalNameToken);

			var modifiers = isConstant
				? SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ConstKeyword))
			                   : default(SyntaxTokenList);

			var declarationStatement = SyntaxFactory.LocalDeclarationStatement(
				modifiers,
				SyntaxFactory.VariableDeclaration(
					this.GetTypeSyntax(document, expression, isConstant, options, cancellationToken),
					SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(
						newLocalNameToken.WithAdditionalAnnotations(RenameAnnotation.Create()),
						null,
						SyntaxFactory.EqualsValueClause(expression.WithoutTrailingTrivia().WithoutLeadingTrivia())))));

			var anonymousMethodParameters = GetAnonymousMethodParameters(document, expression, cancellationToken);
			var lambdas = anonymousMethodParameters.SelectMany(p => p.ContainingSymbol.DeclaringSyntaxReferences.Select(r => r.GetSyntax(cancellationToken)).AsEnumerable())
			                                       .Where(n => n is ParenthesizedLambdaExpressionSyntax || n is SimpleLambdaExpressionSyntax)
			                                       .ToSet();

			var parentLambda = GetParentLambda(expression, lambdas);

			if (parentLambda != null)
			{
				return Task.FromResult(IntroduceLocalDeclarationIntoLambda(
					document, expression, newLocalName, declarationStatement, parentLambda, allOccurrences, cancellationToken));
			}
			else if (IsInExpressionBodiedMember(expression))
			{
				return Task.FromResult(RewriteExpressionBodiedMemberAndIntroduceLocalDeclaration(
					document, expression, newLocalName, declarationStatement, allOccurrences, cancellationToken));
			}
			else
			{
				return IntroduceLocalDeclarationIntoBlockAsync(
					document, expression, newLocalName, declarationStatement, allOccurrences, cancellationToken);
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:48,代码来源:CSharpIntroduceVariableService_IntroduceLocal.cs

示例2: IntroduceLocalAsync

        protected override async Task<Document> IntroduceLocalAsync(
            SemanticDocument document,
            ExpressionSyntax expression,
            bool allOccurrences,
            bool isConstant,
            CancellationToken cancellationToken)
        {
            var containerToGenerateInto = GetContainerToGenerateInto(document, expression, cancellationToken);

            var newLocalNameToken = GenerateUniqueLocalName(
                document, expression, isConstant, containerToGenerateInto, cancellationToken);
            var newLocalName = SyntaxFactory.IdentifierName(newLocalNameToken);

            var modifiers = isConstant
                ? SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ConstKeyword))
                : default(SyntaxTokenList);

            var options = await document.Document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

            var declarationStatement = SyntaxFactory.LocalDeclarationStatement(
                modifiers,
                SyntaxFactory.VariableDeclaration(
                    this.GetTypeSyntax(document, options, expression, isConstant, cancellationToken),
                    SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(
                        newLocalNameToken.WithAdditionalAnnotations(RenameAnnotation.Create()),
                        null,
                        SyntaxFactory.EqualsValueClause(expression.WithoutTrailingTrivia().WithoutLeadingTrivia())))));

            switch (containerToGenerateInto)
            {
                case BlockSyntax block:
                    return await IntroduceLocalDeclarationIntoBlockAsync(
                        document, block, expression, newLocalName, declarationStatement, allOccurrences, cancellationToken).ConfigureAwait(false);

                case ArrowExpressionClauseSyntax arrowExpression:
                    return RewriteExpressionBodiedMemberAndIntroduceLocalDeclaration(
                        document, arrowExpression, expression, newLocalName,
                        declarationStatement, allOccurrences, cancellationToken);

                case LambdaExpressionSyntax lambda:
                    return IntroduceLocalDeclarationIntoLambda(
                        document, lambda, expression, newLocalName, declarationStatement, 
                        allOccurrences, cancellationToken);
            }

            throw new InvalidOperationException();
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:47,代码来源:CSharpIntroduceVariableService_IntroduceLocal.cs

示例3: CreateIsNotNothingBinaryExpression

 BinaryExpressionSyntax CreateIsNotNothingBinaryExpression(ExpressionSyntax identifier)
 {
     return SyntaxFactory.BinaryExpression(SyntaxKind.IsNotExpression, identifier.WithoutTrailingTrivia(), SyntaxFactory.Token(SyntaxKind.IsNotKeyword), SyntaxFactory.LiteralExpression(SyntaxKind.NothingLiteralExpression, SyntaxFactory.Token(SyntaxKind.NothingKeyword)));
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:4,代码来源:AddCheckForNothingCodeRefactoringProvider.cs


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