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


C# Syntax.ArgumentSyntax类代码示例

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


ArgumentSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ArgumentSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Applicable

        public static bool Applicable(SemanticModel semanticModel, ArgumentSyntax argument, IEnumerable<ParameterSyntax> parameters)
        {
            var symbolInfo = semanticModel.GetSymbolInfo(argument.Expression);
            var symbol = symbolInfo.Symbol;

            if (symbol == null)
            {
                return true;
            }

            if (symbol.Kind != SymbolKind.Field &&
                symbol.Kind != SymbolKind.Parameter &&
                symbol.Kind != SymbolKind.Local)
            {
                return false;
            }

            var field = symbol as IFieldSymbol;
            if (field != null)
            {
                return !field.IsReadOnly;
            }

            return true;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:25,代码来源:AddOutOrRefCodeAction.cs

示例2: 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

示例3: TryGetParameterSymbol

        public static bool TryGetParameterSymbol(ArgumentSyntax argument, ArgumentListSyntax argumentList,
            IMethodSymbol method, out IParameterSymbol parameter)
        {
            parameter = null;
            if (!argumentList.Arguments.Contains(argument) ||
                method == null ||
                method.IsVararg)
            {
                return false;
            }

            if (argument.NameColon != null)
            {
                parameter = method.Parameters
                    .FirstOrDefault(symbol => symbol.Name == argument.NameColon.Name.Identifier.ValueText);
                return parameter != null;
            }

            var argumentIndex = argumentList.Arguments.IndexOf(argument);
            var parameterIndex = argumentIndex;

            if (parameterIndex >= method.Parameters.Length)
            {
                var lastParameter = method.Parameters.Last();
                parameter = lastParameter.IsParams ? lastParameter : null;
                return parameter != null;
            }
            parameter = method.Parameters[parameterIndex];
            return true;
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:30,代码来源:MethodParameterLookup.cs

示例4: FormatXmlAsync

		private async Task<Document> FormatXmlAsync(Document document, ArgumentSyntax argSntax, CancellationToken cancellationToken)
		{
			var root = await document.GetSyntaxRootAsync(cancellationToken);
			var tree = root.SyntaxTree;

			//Get the character position of the ArgumentSyntax
			FileLinePositionSpan position = tree.GetLineSpan(argSntax.Span);
			int cSpace = position.StartLinePosition.Character;

			//Get the parent VariableDeclaration to figure out the preceeding trivia since we can't 
			//get the column position from GetLineSpan (bug?)
			var parent = argSntax.Ancestors().Where(t => t.IsKind(SyntaxKind.VariableDeclaration)).FirstOrDefault();
			var parentTrivia = parent.GetLeadingTrivia().ToFullString();

			var xml = argSntax.Expression.GetFirstToken().ValueText;
			var newXml = FormatXml(xml);

			//Process each line of the formatted XML and prepend the parent trivia & spaces
			string[] xmlLines = newXml.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
			for (int i = 1; i < xmlLines.Length; i++)
			{
				xmlLines[i] = parentTrivia + new String(' ', (cSpace - 14)) + xmlLines[i];
			}

			newXml = String.Join("\r\n", xmlLines);
			newXml = "@\"" + newXml + "\"";

			var newNode = SyntaxFactory.Argument(null, SyntaxFactory.Token(SyntaxKind.None), SyntaxFactory.IdentifierName(newXml));
			var newRoot = root.ReplaceNode(argSntax, newNode);
			return document.WithSyntaxRoot(newRoot);
		}
开发者ID:modulexcite,项目名称:GoingBeyondReSharperWithRoslyn_Demo,代码行数:31,代码来源:CodeRefactoringProvider.cs

示例5: GetParameterSymbol

        public static IParameterSymbol GetParameterSymbol(ArgumentSyntax argument, ArgumentListSyntax argumentList, IMethodSymbol method)
        {
            if (!argumentList.Arguments.Contains(argument) ||
                method == null)
            {
                return null;
            }

            if (argument.NameColon != null)
            {
                return method.Parameters
                    .FirstOrDefault(symbol => symbol.Name == argument.NameColon.Name.Identifier.ValueText);
            }

            var argumentIndex = argumentList.Arguments.IndexOf(argument);
            var parameterIndex = argumentIndex;

            if (parameterIndex >= method.Parameters.Length)
            {
                var p = method.Parameters.Last();
                return p.IsParams ? p : null;
            }
            var parameter = method.Parameters[parameterIndex];
            return parameter;
        }
开发者ID:jakobehn,项目名称:sonarlint-vs,代码行数:25,代码来源:MethodParameterLookup.cs

示例6: UseDeclarationExpression

        private async Task<Document> UseDeclarationExpression(Document document, ArgumentSyntax argument, VariableDeclaratorSyntax declarator,
              CancellationToken cancellationToken)
        {
            // get variable declaration
            var declaration = declarator.Parent;

            // get statement which contains both local declaration statement and method call with out argument
            var statement = DiagnosticAnalyzer.GetContainingStatement(declaration.Parent);

            // remove entire local declaration statement or just single variable declaration
            // depending on how many variables are declared within single local declaration statement
            var nodeToRemove = declaration.ChildNodes().OfType<VariableDeclaratorSyntax>().Count() > 1 ? declarator : declaration.Parent;
            var newStatement = statement.RemoveNode(nodeToRemove, SyntaxRemoveOptions.KeepEndOfLine);

            // get variable type
            var type = declaration.ChildNodes().First() as TypeSyntax;
            // create new Declaration Expression using variable type and declarator
            var newDeclarationExpression = SyntaxFactory.DeclarationExpression(type, declarator);
            // fix the trivia aroung Declaration Expression
            var firstToken = newDeclarationExpression.GetFirstToken();
            var leadingTrivia = firstToken.LeadingTrivia;
            var trimmedDeclarationExpression = newDeclarationExpression.ReplaceToken(firstToken, firstToken.WithLeadingTrivia(SyntaxTriviaList.Empty));
            // get ArgumentSyntax from newStatement which is equivalent to argument from original syntax tree
            var newArgument = newStatement.DescendantNodes()
                                          .FirstOrDefault(n => n.IsEquivalentTo(argument));
            // replace argument with new version, containing Declaration Expression
            newStatement = newStatement.ReplaceNode(newArgument.ChildNodes().First(), trimmedDeclarationExpression);

            // get root for current document and replace statement with new version
            var root = await document.GetSyntaxRootAsync(cancellationToken);
            var newRoot = root.ReplaceNode(statement, newStatement);

            // return document with modified syntax
            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:JorisR,项目名称:RoslynCodeFixDemo,代码行数:35,代码来源:CodeFixProvider.cs

示例7: CheckThat

		static InvocationExpressionSyntax CheckThat(INamedTypeSymbol nfluentCheck, ArgumentSyntax argument)
	    {
		    return InvocationExpression(
			    MemberAccessExpression(
				    SyntaxKind.SimpleMemberAccessExpression,
				    nfluentCheck.ToNameSyntax(),
				    IdentifierName("That")),
			    ArgumentList(SingletonSeparatedList(argument)));
	    }
开发者ID:vbfox,项目名称:NFluentConversion,代码行数:9,代码来源:ReplaceNUnitCodeFix.cs

示例8: IsOrdinalOrOrdinalIgnoreCase

            private static bool IsOrdinalOrOrdinalIgnoreCase(ArgumentSyntax argumentSyntax, SemanticModel model)
            {
                var argumentSymbol = model.GetSymbolInfo(argumentSyntax.Expression).Symbol;
                if (argumentSymbol != null)
                {
                    return IsOrdinalOrOrdinalIgnoreCase(argumentSymbol.Name);
                }

                return false;
            }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:10,代码来源:CSharpUseOrdinalStringComparison.cs

示例9: Argument

        public static string Argument(ArgumentSyntax arg)
        {
            var output = SyntaxNode(arg.Expression);

            if (arg.NameColon != null)
            {
                output = SyntaxNode(arg.NameColon.Name) + ": " + output;
            }
            return output;
        }
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:10,代码来源:ArgumentSyntaxParser.cs

示例10: AddOutOrRefCodeAction

 public AddOutOrRefCodeAction(
     Document document,
     SemanticModel semanticModel,
     ArgumentSyntax argument,
     IEnumerable<ParameterSyntax> parameters)
 {
     this.document = document;
     this.semanticModel = semanticModel;
     this.argument = argument;
     this.parameters = parameters;
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:11,代码来源:AddOutOrRefCodeAction.cs

示例11: GetArgumentType

		protected ITypeSymbol GetArgumentType(ArgumentSyntax syntax)
		{
			var symbol = this.semanticModel.GetSpeculativeSymbolInfo(syntax.Expression.SpanStart + this.displacement, syntax.Expression, SpeculativeBindingOption.BindAsExpression).Symbol;

			var property = symbol?.GetType().GetProperty("Type");

			if (property != null)
			{
				return property.GetValue(symbol) as ITypeSymbol;
			}
			
			return this.semanticModel.GetSpeculativeTypeInfo(syntax.Expression.SpanStart + this.displacement, syntax.Expression, SpeculativeBindingOption.BindAsExpression).Type;
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:13,代码来源:MethodInvocationInspector.cs

示例12: 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

示例13: IsPassedToDelegateCreationExpression

            private bool IsPassedToDelegateCreationExpression(ArgumentSyntax argument, ITypeSymbol type)
            {
                if (type.IsDelegateType() &&
                    argument.IsParentKind(SyntaxKind.ArgumentList) &&
                    argument.Parent.IsParentKind(SyntaxKind.ObjectCreationExpression))
                {
                    var objectCreationExpression = (ObjectCreationExpressionSyntax)argument.Parent.Parent;
                    var objectCreationType = _semanticModel.GetTypeInfo(objectCreationExpression).Type;
                    if (objectCreationType.Equals(type))
                    {
                        return true;
                    }
                }

                return false;
            }
开发者ID:RoryVL,项目名称:roslyn,代码行数:16,代码来源:CSharpSimplificationService.Expander.cs

示例14: ComputeRoot

		private Task<Document> ComputeRoot(
			Document document, SyntaxNode root,
			ArgumentSyntax argument, IMethodSymbol methodSymbol) {
			var providenArgumentsList = argument.Parent as ArgumentListSyntax;
			var providenArguments = providenArgumentsList.Arguments;
			var argumentIndex = providenArguments.IndexOf(argument);

			var newArguments = Enumerable.Concat(
				providenArguments.Take(argumentIndex),
				providenArguments.Skip(argumentIndex)
					.Select((arg, index) => {
						var parameterName = methodSymbol.Parameters[index].Name;
						return arg
							.WithNameColon(NameColon(IdentifierName(parameterName)))
							.WithAdditionalAnnotations(Formatter.Annotation, Simplifier.Annotation);
					}));

			var newArgumentList = providenArgumentsList.WithArguments(SeparatedList(newArguments));

			var newRoot = root.ReplaceNode(providenArgumentsList, newArgumentList);
			return Task.FromResult(document.WithSyntaxRoot(newRoot));
		}
开发者ID:vlova,项目名称:RoslynSlides,代码行数:22,代码来源:AddArgumentNameProvider.cs

示例15: IsAccessed

        private bool IsAccessed(
            SemanticModel semanticModel,
            ISymbol outSymbol, 
            BlockSyntax enclosingBlockOfLocalStatement,
            LocalDeclarationStatementSyntax localStatement, 
            ArgumentSyntax argumentNode,
            CancellationToken cancellationToken)
        {
            var localStatementStart = localStatement.Span.Start;
            var argumentNodeStart = argumentNode.Span.Start;
            var variableName = outSymbol.Name;

            // Walk the block that the local is declared in looking for accesses.
            // We can ignore anything prior to the actual local declaration point,
            // and we only need to check up until we reach the out-argument.
            foreach (var descendentNode in enclosingBlockOfLocalStatement.DescendantNodes())
            {
                var descendentStart = descendentNode.Span.Start;
                if (descendentStart <= localStatementStart)
                {
                    // This node is before the local declaration.  Can ignore it entirely as it could
                    // not be an access to the local.
                    continue;
                }

                if (descendentStart >= argumentNodeStart)
                {
                    // We reached the out-var.  We can stop searching entirely.
                    break;
                }

                if (descendentNode.IsKind(SyntaxKind.IdentifierName))
                {
                    // See if this looks like an accessor to the local variable syntactically.
                    var identifierName = (IdentifierNameSyntax)descendentNode;
                    if (identifierName.Identifier.ValueText == variableName)
                    {
                        // Confirm that it is a access of the local.
                        var symbol = semanticModel.GetSymbolInfo(identifierName, cancellationToken).Symbol;
                        if (outSymbol.Equals(symbol))
                        {
                            // We definitely accessed the local before the out-argument.  We 
                            // can't inline this local.
                            return true;
                        }
                    }
                }
            }

            // No accesses detected
            return false;
        }
开发者ID:otawfik-ms,项目名称:roslyn,代码行数:52,代码来源:CSharpInlineDeclarationDiagnosticAnalyzer.cs


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