本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ArgumentSyntax类的具体用法?C# ArgumentSyntax怎么用?C# ArgumentSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArgumentSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ArgumentSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: GetArgumentValue
static SyntaxNode GetArgumentValue(ArgumentSyntax argument)
{
return argument.Expression;
}
开发者ID:jthelin,项目名称:Nake,代码行数:4,代码来源:ProxyInvocation.cs
示例17: GetArgumentName
static string GetArgumentName(ArgumentSyntax argument)
{
return argument.NameColon != null
? argument.NameColon.Name.Identifier.ValueText
: "";
}
开发者ID:jthelin,项目名称:Nake,代码行数:6,代码来源:ProxyInvocation.cs
示例18: FormatArgument
static string FormatArgument(ArgumentSyntax argument)
{
return string.Format(@"new Nake.TaskArgument(""{0}"", {1})",
GetArgumentName(argument), GetArgumentValue(argument));
}
开发者ID:jthelin,项目名称:Nake,代码行数:5,代码来源:ProxyInvocation.cs
示例19: GetIsInstanceOfTypeCall
private static InvocationExpressionSyntax GetIsInstanceOfTypeCall(InvocationExpressionSyntax invocation,
ExpressionSyntax typeInstance, ArgumentSyntax getTypeCallInArgument)
{
return SyntaxFactory.InvocationExpression(
SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
typeInstance,
SyntaxFactory.IdentifierName("IsInstanceOfType")).WithTriviaFrom(invocation.Expression),
SyntaxFactory.ArgumentList(
SyntaxFactory.SeparatedList(new[]
{
SyntaxFactory.Argument(
GetExpressionFromGetType(getTypeCallInArgument.Expression)).WithTriviaFrom(getTypeCallInArgument)
}))
.WithTriviaFrom(invocation.ArgumentList))
.WithTriviaFrom(invocation);
}
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:17,代码来源:GetTypeWithIsAssignableFromCodeFixProvider.cs
示例20: CreateEmptyRule
internal static FieldDeclarationSyntax CreateEmptyRule(SyntaxGenerator generator, string idName="Change me to the name of the above constant", string titleDefault="Enter a title for this diagnostic", string messageDefault="Enter a message to be displayed with this diagnostic",
string categoryDefault="Enter a category for this diagnostic (e.g. Formatting)", ExpressionSyntax severityDefault=null, ExpressionSyntax enabledDefault=null)
{
if (severityDefault == null)
{
severityDefault = generator.DefaultExpression(SyntaxFactory.ParseTypeName("DiagnosticSeverity")) as ExpressionSyntax;
}
if (enabledDefault == null)
{
enabledDefault = generator.DefaultExpression(generator.TypeExpression(SpecialType.System_Boolean)) as ExpressionSyntax;
}
var type = SyntaxFactory.ParseTypeName("DiagnosticDescriptor");
var arguments = new ArgumentSyntax[6];
var whitespace = " ";
var id = generator.LiteralExpression(idName);
var idArg = generator.Argument("id", RefKind.None, id).WithLeadingTrivia(SyntaxFactory.CarriageReturnLineFeed, SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
arguments[0] = idArg;
var title = generator.LiteralExpression(titleDefault);
var titleArg = generator.Argument("title", RefKind.None, title).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
arguments[1] = titleArg;
var message = generator.LiteralExpression(messageDefault);
var messageArg = generator.Argument("messageFormat", RefKind.None, message).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
arguments[2] = messageArg;
var category = generator.LiteralExpression(categoryDefault);
var categoryArg = generator.Argument("category", RefKind.None, category).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
arguments[3] = categoryArg;
var defaultSeverityArg = generator.Argument("defaultSeverity", RefKind.None, severityDefault).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
arguments[4] = defaultSeverityArg;
var enabledArg = generator.Argument("isEnabledByDefault", RefKind.None, enabledDefault).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
arguments[5] = enabledArg;
var identifier = SyntaxFactory.ParseToken("spacingRule");
var separators = new List<SyntaxToken>();
var separator = SyntaxFactory.ParseToken(",").WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed);
separators.Add(separator);
separators.Add(separator);
separators.Add(separator);
separators.Add(separator);
separators.Add(separator);
var argumentsNewLines = SyntaxFactory.SeparatedList(arguments, separators);
var argumentList = SyntaxFactory.ArgumentList(argumentsNewLines);
var value = SyntaxFactory.ObjectCreationExpression(type, argumentList, null);
var initializer = SyntaxFactory.EqualsValueClause(value);
var variables = new SeparatedSyntaxList<VariableDeclaratorSyntax>();
var variable = SyntaxFactory.VariableDeclarator(identifier, null, initializer);
variables = variables.Add(variable);
var declaration = SyntaxFactory.VariableDeclaration(type.WithTrailingTrivia(SyntaxFactory.Whitespace(" ")), variables);
var modifiers = SyntaxFactory.TokenList(SyntaxFactory.ParseToken("internal").WithTrailingTrivia(SyntaxFactory.Whitespace(" ")), SyntaxFactory.ParseToken("static").WithTrailingTrivia(SyntaxFactory.Whitespace(" ")));
var rule = SyntaxFactory.FieldDeclaration(new SyntaxList<AttributeListSyntax>(), modifiers, declaration);
return rule;
}
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:65,代码来源:CodeFixProvider.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论