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


C# ArgumentSyntax.WithExpression方法代码示例

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


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

示例1: VisitArgument

        public override SyntaxNode VisitArgument(ArgumentSyntax node)
        {
            var invocationSyntax = node.Parent.Parent as InvocationExpressionSyntax;
            if(invocationSyntax == null)
                return base.VisitArgument(node);
            var memberAccessExpressionSyntax = invocationSyntax.Expression as MemberAccessExpressionSyntax;
            if(memberAccessExpressionSyntax == null)
                return base.VisitArgument(node);
            var methodNameSyntax = memberAccessExpressionSyntax.Name as SimpleNameSyntax;

            var method = model.GetSymbolInfo(methodNameSyntax).Symbol as IMethodSymbol;
            if(method == null)
                return base.VisitArgument(node);
            var argList = (ArgumentListSyntax)node.Parent;
            //TODO check that parameter name preserved if specified, otherwise order can be broken
            var argIndex = argList.Arguments.IndexOf(node);
            var parameterSymbol = method.Parameters[argIndex]; //TODO when there is params argument in method index may be well out of range

            var lambda = node.Expression as LambdaExpressionSyntax;
            if(parameterSymbol.HasAttribute<MetaRewriteLambdaParamAttribute>(model.Compilation) && lambda != null) {
                //TODO error if value is not lambda
                return node.WithExpression(VisitLambdaExpression(lambda));
            }
            if(parameterSymbol.HasAttribute<MetaRewriteParamAttribute>(model.Compilation))
                return node.WithExpression(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(node.Expression.ToFullString())));
            return base.VisitArgument(node);
        }
开发者ID:VitalyTVA,项目名称:MetaSharp,代码行数:27,代码来源:Rewriter.cs

示例2: VisitArgument

		/// <summary>
		///     Lifts the expression represented by <paramref name="argument" />, if necessary.
		/// </summary>
		public override SyntaxNode VisitArgument(ArgumentSyntax argument)
		{
			if (argument.Parent.Parent is ElementAccessExpressionSyntax)
				return base.VisitArgument(argument);

			var requiresLifting = argument.HasAttribute<LiftExpressionAttribute>(SemanticModel);
			argument = (ArgumentSyntax)base.VisitArgument(argument);

			if (!requiresLifting)
				return argument;

			var expression = SyntaxBuilder.Lambda(Enumerable.Empty<ParameterSyntax>(), argument.Expression).WithTrivia(argument);
			return argument.WithExpression(expression);
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:17,代码来源:LiftedExpressionNormalizer.cs

示例3: VisitArgument

		/// <summary>
		///     Normalizes the <paramref name="argument" />.
		/// </summary>
		public override SyntaxNode VisitArgument(ArgumentSyntax argument)
		{
			// Special case for array accesses, as Roslyn doesn't return a symbol for the argument
			if (argument.Parent.Parent is ElementAccessExpressionSyntax)
			{
				var arrayExpression = ((ElementAccessExpressionSyntax)argument.Parent.Parent).Expression;
				if (SemanticModel.GetTypeInfo(arrayExpression).Type.TypeKind == TypeKind.Array)
					return base.VisitArgument(argument);
			}

			var parameterSymbol = argument.GetParameterSymbol(SemanticModel);
			if (parameterSymbol.RefKind != RefKind.None)
				return base.VisitArgument(argument);

			var parameterType = DetermineType(parameterSymbol.Type);
			if (parameterType == ExpressionType.Other)
				return base.VisitArgument(argument);

			return argument.WithExpression(ReplaceImplicitConversion(parameterType, argument.Expression));
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:23,代码来源:FormulaNormalizer.cs

示例4: VisitArgument

		/// <summary>
		///   Normalizes the <paramref name="argument" />.
		/// </summary>
		public override SyntaxNode VisitArgument(ArgumentSyntax argument)
		{
			// Special case for array accesses, as Roslyn doesn't return a symbol for the argument
			if (argument.Parent.Parent is ElementAccessExpressionSyntax)
			{
				var arrayExpression = ((ElementAccessExpressionSyntax)argument.Parent.Parent).Expression;
				var kind = SemanticModel.GetTypeInfo(arrayExpression).Type.TypeKind;
				if (kind == TypeKind.Array || kind == TypeKind.Pointer)
					return base.VisitArgument(argument);
			}

			var parameterSymbol = argument.GetParameterSymbol(SemanticModel);
			if (parameterSymbol.RefKind != RefKind.None)
				return base.VisitArgument(argument);

			var arraySymbol = parameterSymbol.Type as IArrayTypeSymbol;
			var isParamsFormula = arraySymbol != null && parameterSymbol.IsParams && IsFormulaType(arraySymbol.ElementType);

			if (!isParamsFormula && !IsFormulaType(parameterSymbol.Type))
				return base.VisitArgument(argument);

			return argument.WithExpression(ReplaceImplicitConversion(argument.Expression));
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:26,代码来源:FormulaNormalizer.cs


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