本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeSyntax.GetLocation方法的具体用法?C# AttributeSyntax.GetLocation怎么用?C# AttributeSyntax.GetLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax
的用法示例。
在下文中一共展示了AttributeSyntax.GetLocation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Analyze
private static IEnumerable<Diagnostic> Analyze(AttributeSyntax mapperAttribute, SemanticModel semModel)
{
if (mapperAttribute?.Name.ToString() != "Mapper")
{
yield break;
}
var symbol = semModel.GetSymbolInfo(mapperAttribute).Symbol as IMethodSymbol;
if (!symbol?.ToString().StartsWith("NCR.Engage.RoslynAnalysis.MapperAttribute") ?? true)
{
yield break;
}
var sourceClass = GetSourceSymbols(semModel, mapperAttribute);
if (sourceClass == null)
{
yield break;
}
var sourceProperties = GetSourceProperties(semModel, sourceClass.Item1, sourceClass.Item2);
var mapperClass = GetMapperClass(semModel, mapperAttribute);
if (mapperClass == null)
{
yield break;
}
foreach (var sourceProperty in sourceProperties)
{
if (IsPropertyMentioned(sourceProperty, mapperAttribute))
{
continue;
}
var sourcePropertyName = $"'{sourceProperty.Type} {sourceClass.Item1.Name}.{sourceProperty.Name}'";
var mapperClassName = $"'{mapperClass.Name}'";
yield return Diagnostic.Create(PropertyNotMapped, mapperAttribute.GetLocation(), sourcePropertyName, mapperClassName);
}
}
示例2: VisitAttribute
public override SyntaxNode VisitAttribute(AttributeSyntax node)
{
int id;
string description;
if (!CSharpAttributeUtil.TryGetInformation(node, out id, out description))
{
return node;
}
var info = _workItemUtil.GetUpdatedWorkItemInfo(_filePath, node.GetLocation().GetMappedLineSpan(), id, description);
if (info.HasValue)
{
node = CSharpAttributeUtil.UpdateAttribute(node, info.Value.Id, info.Value.Description);
}
return node;
}
示例3: GetSingleBody
public static ExpressionSyntax GetSingleBody(SyntaxNodeAnalysisContext context, string ident, AttributeSyntax att, MemberDeclarationSyntax member)
{
if (member is MethodDeclarationSyntax)
{
var method = (MethodDeclarationSyntax)member;
if (method.ExpressionBody != null)
return method.ExpressionBody.Expression;
return OnlyReturn(context, ident, att, method.Body.Statements);
}
else if (member is PropertyDeclarationSyntax)
{
var property = (PropertyDeclarationSyntax)member;
if (property.ExpressionBody != null)
return property.ExpressionBody.Expression;
var getter = property.AccessorList.Accessors.SingleOrDefault(a => a.Kind() == SyntaxKind.GetAccessorDeclaration);
if (getter == null)
{
Diagnostic(context, ident, att.GetLocation(), "no getter");
return null;
}
if (getter.Body == null)
{
Diagnostic(context, ident, getter.GetLocation(), "no getter body");
return null;
}
return OnlyReturn(context, ident, att, getter.Body.Statements);
}
Diagnostic(context, ident, att.GetLocation(), "no property or method");
return null;
}
示例4: OnlyReturn
internal static ExpressionSyntax OnlyReturn(SyntaxNodeAnalysisContext context, string ident, AttributeSyntax att, SyntaxList<StatementSyntax> statements)
{
var only = statements.Only();
if (only == null)
{
Diagnostic(context, ident, att.GetLocation(), statements.Count + " statements");
return null;
}
var ret = only as ReturnStatementSyntax;
if (ret == null)
{
Diagnostic(context, ident, only.GetLocation(), "no return");
return null;
}
if (ret.Expression == null)
{
Diagnostic(context, ident, only.GetLocation(), "no return expression");
return null;
}
return ret.Expression;
}
示例5: AddToDictionary
private void AddToDictionary(AttributeSyntax attributeSyntax, string name, Dictionary<string, SyntaxNode> dictionary, SemanticModel semanticModel, INamedTypeSymbol predefinedType)
{
var argument = attributeSyntax.ArgumentList.Arguments.FirstOrDefault(arg => arg.NameEquals?.Name?.Identifier.Text == name);
if (argument != null)
{
MemberAccessExpressionSyntax memberAccess = argument.Expression as MemberAccessExpressionSyntax;
IdentifierNameSyntax nameSyntax = memberAccess?.Expression as IdentifierNameSyntax;
if (memberAccess == null || nameSyntax == null)
throw new GenerationException(attributeSyntax.GetLocation(), $"The assignment to the Keyword, Task and Opcode arguments must be a simple member access expression.");
TypeInfo ti = semanticModel.GetTypeInfo(memberAccess.Expression);
if (!predefinedType.Equals(ti.Type))
dictionary[memberAccess.Name.Identifier.Text] = argument.Expression;
}
}
开发者ID:modulexcite,项目名称:EventSourceGenerator,代码行数:15,代码来源:EventSourceGenerator.CollectedGenerationInfo.cs