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


C# AttributeSyntax.GetLocation方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:NCR-Engage,项目名称:MapEnforcerAnalyzer,代码行数:42,代码来源:DiagnosticAnalyzer.cs

示例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;
        }
开发者ID:jaredpar,项目名称:random,代码行数:17,代码来源:CSharpTypes.cs

示例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;
        }
开发者ID:signumsoftware,项目名称:framework,代码行数:38,代码来源:ExpressionFieldAnalyzer.cs

示例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;
        }
开发者ID:signumsoftware,项目名称:framework,代码行数:25,代码来源:ExpressionFieldAnalyzer.cs

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


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