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


C# INamedTypeSymbol.GetAttributes方法代码示例

本文整理汇总了C#中INamedTypeSymbol.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.GetAttributes方法的具体用法?C# INamedTypeSymbol.GetAttributes怎么用?C# INamedTypeSymbol.GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在INamedTypeSymbol的用法示例。


在下文中一共展示了INamedTypeSymbol.GetAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AnalyzeSymbol

        public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
        {
            if (symbol.TypeKind != TypeKind.Enum)
            {
                return;
            }

            var flagsAttribute = WellKnownTypes.FlagsAttribute(compilation);
            if (flagsAttribute == null)
            {
                return;
            }

            var zeroValuedFields = GetZeroValuedFields(symbol).ToImmutableArray();

            bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass == flagsAttribute);
            if (hasFlagsAttribute)
            {
                CheckFlags(symbol, zeroValuedFields, addDiagnostic);
            }
            else
            {
                CheckNonFlags(symbol, zeroValuedFields, addDiagnostic);
            }
        }
开发者ID:pheede,项目名称:roslyn,代码行数:25,代码来源:CA1008DiagnosticAnalyzer.cs

示例2: IsFlagsEnum

        private bool IsFlagsEnum(INamedTypeSymbol typeSymbol)
        {
            if (typeSymbol.TypeKind != TypeKind.Enum)
            {
                return false;
            }

            foreach (var attribute in typeSymbol.GetAttributes())
            {
                var ctor = attribute.AttributeConstructor;
                if (ctor != null)
                {
                    var type = ctor.ContainingType;
                    if (!ctor.Parameters.Any() && type.Name == "FlagsAttribute")
                    {
                        var containingSymbol = type.ContainingSymbol;
                        if (containingSymbol.Kind == SymbolKind.Namespace &&
                            containingSymbol.Name == "System" &&
                            ((INamespaceSymbol)containingSymbol.ContainingSymbol).IsGlobalNamespace)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:28,代码来源:AbstractFlagsEnumGenerator.cs

示例3: GetApplicableAttributes

        internal static IEnumerable<AttributeData> GetApplicableAttributes(INamedTypeSymbol type)
        {
            var attributes = new List<AttributeData>();

            while (type != null)
            {
                attributes.AddRange(type.GetAttributes());

                type = type.BaseType;
            }

            return attributes;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:13,代码来源:AttributeHelpers.cs

示例4: AnalyzeSymbol

        private static void AnalyzeSymbol(INamedTypeSymbol symbol, INamedTypeSymbol attributeType, INamedTypeSymbol attributeUsageAttributeType, Action<Diagnostic> addDiagnostic)
        {
            if (symbol.IsAbstract || !symbol.GetBaseTypesAndThis().Contains(attributeType))
            {
                return;
            }

            bool hasAttributeUsageAttribute = symbol.GetAttributes().Any(attribute => attribute.AttributeClass.Equals(attributeUsageAttributeType));
            if (!hasAttributeUsageAttribute)
            {
                addDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name));
            }
        }
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:13,代码来源:MarkAttributesWithAttributeUsage.cs

示例5: AnalyzeSymbol

        public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            if (symbol != null &&
                symbol.TypeKind == TypeKind.Enum &&
                symbol.DeclaredAccessibility == Accessibility.Public)
            {
                var flagsAttributeType = WellKnownTypes.FlagsAttribute(compilation);
                if (flagsAttributeType == null)
                {
                    return;
                }

                IList<ulong> memberValues;
                if (DiagnosticHelpers.TryGetEnumMemberValues(symbol, out memberValues))
                {
                    bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass == flagsAttributeType);
                    if (hasFlagsAttribute)
                    {
                        // Check "CA2217: Do not mark enums with FlagsAttribute"
                        IEnumerable<ulong> missingValues;
                        if (!ShouldBeFlags(memberValues, out missingValues))
                        {
                            Contract.ThrowIfNull(missingValues);

                            var missingValuesString = missingValues.Select(v => v.ToString()).Aggregate((i, j) => i + ", " + j);
                            var location = GetDiagnosticLocation(symbol.DeclaringSyntaxReferences[0].GetSyntax());
                            addDiagnostic(location.CreateDiagnostic(Rule2217, symbol.Name, missingValuesString));
                        }
                    }
                    else
                    {
                        // Check "CA1027: Mark enums with FlagsAttribute"
                        // Ignore continguous value enums to reduce noise.
                        if (!IsContiguous(memberValues) && ShouldBeFlags(memberValues))
                        {
                            var location = GetDiagnosticLocation(symbol.DeclaringSyntaxReferences[0].GetSyntax());
                            addDiagnostic(location.CreateDiagnostic(Rule1027, symbol.Name));
                        }
                    }
                }
            }
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:42,代码来源:EnumWithFlagsDiagnosticAnalyzer.cs

示例6: GenerateProxyInterface

      public InterfaceDeclarationSyntax GenerateProxyInterface(SemanticModel semanticModel, SyntaxGenerator generator, INamedTypeSymbol sourceServiceInterface, string targetInterfaceName, Accessibility accessibility = Accessibility.Public, bool inheritServiceInterface = false, bool suppressAsyncMethodGeneration = false, bool suppressWarningComments = false)
      {
         SyntaxNode targetInterface = generator.InterfaceDeclaration(targetInterfaceName, accessibility: accessibility);

         targetInterface = generator.AddAttributes(targetInterface, sourceServiceInterface.GetAttributes().Select(attr => generator.Attribute(attr)));

         foreach (SyntaxNode method in GetOperationContractMethodDeclarations(semanticModel, generator, sourceServiceInterface, true, !inheritServiceInterface, suppressAsyncMethodGeneration))
         {
            targetInterface = generator.AddMembers(targetInterface, generator.AddWarningCommentIf(!suppressWarningComments, method));
         }

         if (inheritServiceInterface)
         {
            targetInterface = generator.AddInterfaceType(targetInterface, generator.TypeExpression(sourceServiceInterface));
         }

         targetInterface = AddGeneratedCodeAttribute(generator, targetInterface);

         targetInterface = generator.AddWarningCommentIf(!suppressWarningComments, targetInterface);

         return (InterfaceDeclarationSyntax)targetInterface;
      }
开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:22,代码来源:ClientProxyGenerator.ProxyInterface.cs

示例7: AnalyzeSymbol

        protected override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var attributeUsageAttribute = WellKnownTypes.AttributeUsageAttribute(compilation);
            if (attributeUsageAttribute == null)
            {
                return;
            }

            if (symbol.IsAbstract || !symbol.IsAttribute())
            {
                return;
            }

            if (attributeUsageAttribute == null)
            {
                return;
            }

            var hasAttributeUsageAttribute = symbol.GetAttributes().Any(attribute => attribute.AttributeClass == attributeUsageAttribute);
            if (!hasAttributeUsageAttribute)
            {
                addDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name));
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:24,代码来源:CA1018DiagnosticAnalyzer.cs

示例8: HasCodeFix

        private CodeFixStatus HasCodeFix(string diagnosticId, INamedTypeSymbol classSymbol, out string noCodeFixReason)
        {
            CodeFixStatus status;

            noCodeFixReason = null;

            var noCodeFixAttribute = classSymbol.GetAttributes().SingleOrDefault(x => x.AttributeClass == this.noCodeFixAttributeTypeSymbol);

            bool hasCodeFix = noCodeFixAttribute == null;
            if (!hasCodeFix)
            {
                status = CodeFixStatus.NotImplemented;
                if (noCodeFixAttribute.ConstructorArguments.Length > 0)
                {
                    noCodeFixReason = noCodeFixAttribute.ConstructorArguments[0].Value as string;
                }
            }
            else
            {
                // Check if the code fix actually exists
                hasCodeFix = this.CodeFixProviders.Any(x => x.FixableDiagnosticIds.Contains(diagnosticId));

                status = hasCodeFix ? CodeFixStatus.Implemented : CodeFixStatus.NotYetImplemented;
            }

            return status;
        }
开发者ID:sharwell,项目名称:StyleCop.Analyzers.Status,代码行数:27,代码来源:SolutionReader.cs

示例9: GenerateAttributeDeclarations

 private static SyntaxList<AttributeListSyntax> GenerateAttributeDeclarations(
     INamedTypeSymbol namedType, CodeGenerationOptions options)
 {
     return AttributeGenerator.GenerateAttributeLists(namedType.GetAttributes(), options);
 }
开发者ID:nemec,项目名称:roslyn,代码行数:5,代码来源:NamedTypeGenerator.cs

示例10: HasComSourceInterfacesAttribute

 private bool HasComSourceInterfacesAttribute(INamedTypeSymbol symbol)
 {
     return symbol.GetAttributes().FirstOrDefault(a => a.AttributeClass == this.comSourceInterfacesAttribute) != null;
 }
开发者ID:riversky,项目名称:roslyn,代码行数:4,代码来源:CA1003DiagnosticAnalyzer.cs

示例11: GetCodeGeneratorTypeNameForAttribute

        private static string GetCodeGeneratorTypeNameForAttribute(INamedTypeSymbol attributeType)
        {
            if (attributeType != null)
            {
                foreach (var generatorCandidateAttribute in attributeType.GetAttributes())
                {
                    if (generatorCandidateAttribute.AttributeClass.Name == typeof(Generators.CodeGenerationAttribute).Name)
                    {
                        return (string)generatorCandidateAttribute.ConstructorArguments.Single().Value;
                    }
                }
            }

            return null;
        }
开发者ID:gitter-badger,项目名称:ImmutableObjectGraph,代码行数:15,代码来源:DocumentTransform.cs

示例12: GetClassAttributesWithTranslation

 /// <summary>
 /// Gets all the attributes from the specified <paramref name="sourceClass"/>, with special handling and translation 
 /// of a TemplateEventSourceAttribute which will be translated into an EventSourceAttribute with additional arguments stripped away.
 /// </summary>
 /// <param name="sourceClass">The clas from which to retrieve and translate attribtues.</param>
 /// <returns>A list of all attributes that should be applied to the target class.</returns>
 private IEnumerable<SyntaxNode> GetClassAttributesWithTranslation(INamedTypeSymbol sourceClass, EventSourceTypeInfo baseTypeInfo)
 {
    foreach (var attributeData in sourceClass.GetAttributes())
    {
       if (attributeData.AttributeClass.Name.Equals(TemplateEventSourceAttributeName))
       {
          yield return m_generator.Attribute(baseTypeInfo.EventSourceAttributeType.GetFullName(),
             attributeData.ConstructorArguments.Select(arg => m_generator.AttributeArgument(m_generator.LiteralExpression(arg.Value)))
             .Concat(
                attributeData.NamedArguments.Where(arg => !typeof(GenerationOptions).GetProperties().Any(p => p.Name.Equals(arg.Key)))
                .Select(arg => m_generator.AttributeArgument(arg.Key, m_generator.LiteralExpression(arg.Value.Value)))
             )
          );
       }
       else
       {
          yield return m_generator.Attribute(attributeData);
       }
    }
 }
开发者ID:modulexcite,项目名称:EventSourceGenerator-1,代码行数:26,代码来源:EventSourceGenerator.cs

示例13: IsNonStaticClassWithNoAttributes

 private static bool IsNonStaticClassWithNoAttributes(INamedTypeSymbol namedType)
 {
     return namedType.IsClass() &&
         !namedType.IsStatic &&
         !namedType.GetAttributes().Any();
 }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:6,代码来源:ClassNotInstantiatable.cs

示例14: GetContextFromClass

        static RoslynReflectionAllowedContext GetContextFromClass(INamedTypeSymbol symbol)
        {
            RoslynReflectionAllowedContext surroundingContext = RoslynReflectionAllowedContext.None;
            var surroundingClassAttributes = symbol.GetAttributes();
            if (surroundingClassAttributes.Any(a => a.AttributeClass.GetFullName() == typeof(DiagnosticAnalyzerAttribute).FullName))
                surroundingContext = RoslynReflectionAllowedContext.Analyzers;
            else if (surroundingClassAttributes.Any(a => a.AttributeClass.GetFullName() == typeof(ExportCodeFixProviderAttribute).FullName))
                surroundingContext = RoslynReflectionAllowedContext.CodeFixes;
            else if (surroundingClassAttributes.Any(a => a.AttributeClass.GetFullName() == typeof(ExportCodeRefactoringProviderAttribute).FullName))
                surroundingContext = RoslynReflectionAllowedContext.CodeFixes;

            return surroundingContext;
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:13,代码来源:RoslynUsageAnalyzer.cs

示例15: AnalyzeSymbol

        private static void AnalyzeSymbol(INamedTypeSymbol symbol, INamedTypeSymbol flagsAttributeType, Action<Diagnostic> addDiagnostic)
        {
            if (symbol != null &&
                symbol.TypeKind == TypeKind.Enum &&
                symbol.DeclaredAccessibility == Accessibility.Public)
            {
                IList<ulong> memberValues;
                if (EnumHelpers.TryGetEnumMemberValues(symbol, out memberValues))
                {
                    bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass == flagsAttributeType);
                    if (hasFlagsAttribute)
                    {
                        // Check "CA2217: Do not mark enums with FlagsAttribute"
                        IEnumerable<ulong> missingValues;
                        if (!ShouldBeFlags(memberValues, out missingValues))
                        {
                            Debug.Assert(missingValues != null);

                            string missingValuesString = missingValues.Select(v => v.ToString()).Aggregate((i, j) => i + ", " + j);
                            addDiagnostic(symbol.CreateDiagnostic(Rule2217, symbol.Name, missingValuesString));
                        }
                    }
                    else
                    {
                        // Check "CA1027: Mark enums with FlagsAttribute"
                        // Ignore contiguous value enums to reduce noise.
                        if (!IsContiguous(memberValues) && ShouldBeFlags(memberValues))
                        {
                            addDiagnostic(symbol.CreateDiagnostic(Rule1027, symbol.Name));
                        }
                    }
                }
            }
        }
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:34,代码来源:EnumWithFlagsAttribute.cs


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