本文整理汇总了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);
}
示例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);
}
示例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));
}
示例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));
}