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


C# ISymbol.GetAttributes方法代码示例

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


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

示例1: ContainedIn

        public bool ContainedIn(ISymbol symbol)
        {
            bool result = false;
            var attributes = symbol.GetAttributes();
            foreach (var attribute in attributes)
            {
                INamedTypeSymbol attributeClass = attribute.AttributeClass;
                if (Uid != VisitorHelper.GetId(attributeClass))
                {
                    continue;
                }

                // arguments need to be a total match of the config
                IEnumerable<string> arguments = attribute.ConstructorArguments.Select(arg => GetLiteralString(arg));
                if (!ConstructorArguments.SequenceEqual(arguments))
                {
                    continue;
                }

                // namedarguments need to be a superset of the config
                Dictionary<string, string> namedArguments = attribute.NamedArguments.ToDictionary(pair => pair.Key, pair => GetLiteralString(pair.Value));
                if (!ConstructorNamedArguments.Except(namedArguments).Any())
                {
                    result = true;
                    break;
                }
            }

            return result;
        }
开发者ID:dotnet,项目名称:docfx,代码行数:30,代码来源:AttributeFilterInfo.cs

示例2: ItemsToIgnoreFromAttributes

 public static IEnumerable<NameAndLocation> ItemsToIgnoreFromAttributes(ISymbol symbol,
                                                                        IEnumerable<Type> attributes) =>
     symbol.GetAttributes()
           .Where(a => attributes.TryFirst(t => MatchAttributeName(t, a.AttributeClass.Name)).HasValue)
           .SelectMany(attribute =>
                           (attribute.ApplicationSyntaxReference.GetSyntax() as AttributeSyntax).ArgumentList
                                                                                                .Arguments)
           .Select(argument => new NameAndLocation(argument.ToString().Trim('"'), argument.GetLocation()));
开发者ID:DavidArno,项目名称:Arnolyzer,代码行数:8,代码来源:CommonFunctions.cs

示例3: FindAttributeOfType

 public static AttributeData FindAttributeOfType(ISymbol typeSymbol, Type type)
 {
     foreach (AttributeData attributeData in typeSymbol.GetAttributes())
     {
         if (attributeData.AttributeClass.ToString() ==
             type.FullName)
         {
             return attributeData;
         }
     }
     return null;
 }
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:12,代码来源:AttributeUtils.cs

示例4: IsGeneratedSymbolWithGeneratedCodeAttribute

            internal static bool IsGeneratedSymbolWithGeneratedCodeAttribute(ISymbol symbol, INamedTypeSymbol generatedCodeAttribute)
            {
                Debug.Assert(symbol != null);
                Debug.Assert(generatedCodeAttribute != null);

                // GeneratedCodeAttribute can only be applied once on a symbol.
                // For partial symbols with more than one definition, we must treat them as non-generated code symbols.
                if (symbol.DeclaringSyntaxReferences.Length > 1)
                {
                    return false;
                }

                if (symbol.GetAttributes().Any(a => a.AttributeClass == generatedCodeAttribute))
                {
                    return true;
                }

                return symbol.ContainingSymbol != null && IsGeneratedSymbolWithGeneratedCodeAttribute(symbol.ContainingSymbol, generatedCodeAttribute);
            }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:19,代码来源:AnalyzerDriver.GeneratedCodeUtilities.cs

示例5: GetExtensions

        /// <summary>
        /// Creates transform instances.
        /// </summary>
        /// <param name="symbol">The symbol to create from.</param>
        /// <returns>A collection of extensions.</returns>
        public IEnumerable<IExtension> GetExtensions(ISymbol symbol)
        {
            if (symbol == null)
                yield break;

            var attributes = symbol.GetAttributes();
            if (attributes == null)
                yield break;

            foreach (var attr in attributes)
            {
                // look for extension attribute
                var extAttr = attr.AttributeClass.GetAttributes()
                    .AsEnumerable().SingleOrDefault(aa =>
                        aa.AttributeClass.GetFullName() == _extClassName);

                if (extAttr == null)
                    continue;

                // handler class assembly and type names come from arguments of extension attribute
                var asmName = extAttr.ConstructorArguments.ElementAt(0).Value.ToString();
                var typeName = extAttr.ConstructorArguments.ElementAt(1).Value.ToString();

                // applied attribute arguments are passed directly to handler ctor
                var args = attr.ConstructorArguments.AsEnumerable().Select(p => p.Value);

                // create an instance of the handler class
                var instanceWrapper = Activator.CreateInstance(asmName, typeName, false, 0, null, args.ToArray(), null, null);
                var inst = instanceWrapper.Unwrap() as IExtension;

                if (inst == null)
                    throw new InvalidOperationException("Unable to create transform extension for: " + attr.AttributeClass.GetFullName());

                // support for named arguments (these bind to properties on the handler)
                foreach (var prop in attr.NamedArguments.AsEnumerable())
                    inst.GetType().GetProperty(prop.Key).SetValue(inst, prop.Value.Value, null);

                yield return inst;
            }
        }
开发者ID:JimmyJune,项目名称:blade,代码行数:45,代码来源:ExtensionFactory.cs

示例6: GetRuleDependencyAttributes

 private ImmutableArray<AttributeData> GetRuleDependencyAttributes(ISymbol symbol, IEnumerable<INamedTypeSymbol> ruleDependencyAttributeTypes)
 {
     return GetRuleDependencyAttributes(symbol.GetAttributes(), ruleDependencyAttributeTypes);
 }
开发者ID:modulexcite,项目名称:RuleDependencyAnalyzer,代码行数:4,代码来源:DiagnosticAnalyzer.cs

示例7: GetSymbolAttributes

 private IEnumerable<SyntaxNode> GetSymbolAttributes(ISymbol symbol)
 {
     return symbol.GetAttributes().Select(a => Attribute(a));
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:4,代码来源:SyntaxGenerator.cs

示例8: ParseClassSymbols

        private static void ParseClassSymbols(ParseResult disco, ISymbol symbol)
        {
            foreach (var attrData in symbol.GetAttributes())
            {
                var attrClassSymbol = attrData.AttributeClass;

                // handle errors
                if (attrClassSymbol is IErrorTypeSymbol) continue;
                if (attrData.AttributeConstructor == null) continue;

                var attrClassName = SymbolDisplay.ToDisplayString(attrClassSymbol);
                switch (attrClassName)
                {
                    case "Umbraco.ModelsBuilder.IgnorePropertyTypeAttribute":
                        var propertyAliasToIgnore = (string)attrData.ConstructorArguments[0].Value;
                        disco.SetIgnoredProperty(symbol.Name /*SymbolDisplay.ToDisplayString(symbol)*/, propertyAliasToIgnore);
                        break;
                    case "Umbraco.ModelsBuilder.RenamePropertyTypeAttribute":
                        var propertyAliasToRename = (string)attrData.ConstructorArguments[0].Value;
                        var propertyRenamed = (string)attrData.ConstructorArguments[1].Value;
                        disco.SetRenamedProperty(symbol.Name /*SymbolDisplay.ToDisplayString(symbol)*/, propertyAliasToRename, propertyRenamed);
                        break;
                    // that one causes all sorts of issues with references to Umbraco.Core in Roslyn
                    //case "Umbraco.Core.Models.PublishedContent.PublishedContentModelAttribute":
                    //    var contentAliasToRename = (string)attrData.ConstructorArguments[0].Value;
                    //    disco.SetRenamedContent(contentAliasToRename, symbol.Name /*SymbolDisplay.ToDisplayString(symbol)*/);
                    //    break;
                    case "Umbraco.ModelsBuilder.ImplementContentTypeAttribute":
                        var contentAliasToRename = (string)attrData.ConstructorArguments[0].Value;
                        disco.SetRenamedContent(contentAliasToRename, symbol.Name, true /*SymbolDisplay.ToDisplayString(symbol)*/);
                        break;
                }
            }
        }
开发者ID:nul800sebastiaan,项目名称:Zbu.ModelsBuilder,代码行数:34,代码来源:CodeParser.cs

示例9: AddDescriptionPartAsync

            private async Task AddDescriptionPartAsync(ISymbol symbol)
            {
                if (symbol.GetAttributes().Any(x => x.AttributeClass.MetadataName == "ObsoleteAttribute"))
                {
                    AddDeprecatedPrefix();
                }

                if (symbol is IDynamicTypeSymbol)
                {
                    AddDescriptionForDynamicType();
                }
                else if (symbol is IFieldSymbol)
                {
                    await AddDescriptionForFieldAsync((IFieldSymbol)symbol).ConfigureAwait(false);
                }
                else if (symbol is ILocalSymbol)
                {
                    await AddDescriptionForLocalAsync((ILocalSymbol)symbol).ConfigureAwait(false);
                }
                else if (symbol is IMethodSymbol)
                {
                    AddDescriptionForMethod((IMethodSymbol)symbol);
                }
                else if (symbol is ILabelSymbol)
                {
                    AddDescriptionForLabel((ILabelSymbol)symbol);
                }
                else if (symbol is INamedTypeSymbol)
                {
                    await AddDescriptionForNamedTypeAsync((INamedTypeSymbol)symbol).ConfigureAwait(false);
                }
                else if (symbol is INamespaceSymbol)
                {
                    AddDescriptionForNamespace((INamespaceSymbol)symbol);
                }
                else if (symbol is IParameterSymbol)
                {
                    await AddDescriptionForParameterAsync((IParameterSymbol)symbol).ConfigureAwait(false);
                }
                else if (symbol is IPropertySymbol)
                {
                    AddDescriptionForProperty((IPropertySymbol)symbol);
                }
                else if (symbol is IRangeVariableSymbol)
                {
                    AddDescriptionForRangeVariable((IRangeVariableSymbol)symbol);
                }
                else if (symbol is ITypeParameterSymbol)
                {
                    AddDescriptionForTypeParameter((ITypeParameterSymbol)symbol);
                }
                else if (symbol is IAliasSymbol)
                {
                    await AddDescriptionPartAsync(((IAliasSymbol)symbol).Target).ConfigureAwait(false);
                }
                else
                {
                    AddDescriptionForArbitrarySymbol(symbol);
                }
            }
开发者ID:jkotas,项目名称:roslyn,代码行数:60,代码来源:AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs

示例10: DecodeGlobalSuppressMessageAttributes

        private static void DecodeGlobalSuppressMessageAttributes(Compilation compilation, ISymbol symbol, ISymbol suppressMessageAttribute, GlobalSuppressions globalSuppressions)
        {
            Debug.Assert(symbol is IAssemblySymbol || symbol is IModuleSymbol);

            var attributeInstances = symbol.GetAttributes().Where(a => a.AttributeClass == suppressMessageAttribute);

            foreach (var instance in attributeInstances)
            {
                SuppressMessageInfo info;
                if (!TryDecodeSuppressMessageAttributeData(instance, out info))
                {
                    continue;
                }

                string scopeString = info.Scope != null ? info.Scope.ToLowerInvariant() : null;
                TargetScope scope;

                if (SuppressMessageScopeTypes.TryGetValue(scopeString, out scope))
                {
                    if ((scope == TargetScope.Module || scope == TargetScope.None) && info.Target == null)
                    {
                        // This suppression is applies to the entire compilation
                        globalSuppressions.AddCompilationWideSuppression(info.Id);
                        continue;
                    }
                }
                else
                {
                    // Invalid value for scope
                    continue;
                }

                // Decode Target
                if (info.Target == null)
                {
                    continue;
                }

                foreach (var target in ResolveTargetSymbols(compilation, info.Target, scope))
                {
                    globalSuppressions.AddGlobalSymbolSuppression(target, info.Id);
                }
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:44,代码来源:SuppressMessageAttributeState.cs

示例11: DecodeGlobalSuppressMessageAttributes

        private void DecodeGlobalSuppressMessageAttributes(Compilation compilation, ISymbol symbol, GlobalSuppressions globalSuppressions)
        {
            Debug.Assert(symbol is IAssemblySymbol || symbol is IModuleSymbol);

            var attributes = symbol.GetAttributes().Where(a => a.AttributeClass == this.SuppressMessageAttribute);
            DecodeGlobalSuppressMessageAttributes(compilation, symbol, globalSuppressions, attributes);
        }
开发者ID:redjbishop,项目名称:roslyn,代码行数:7,代码来源:SuppressMessageAttributeState.cs

示例12: IsObsolete

		static bool IsObsolete (ISymbol symbol)
		{
			return symbol.GetAttributes ().Any (attr => attr.AttributeClass.Name == "ObsoleteAttribute" && attr.AttributeClass.ContainingNamespace.GetFullName () == "System");
		}
开发者ID:pjcollins,项目名称:monodevelop,代码行数:4,代码来源:RoslynSymbolCompletionData.cs

示例13: GetNewFieldName

            private static string GetNewFieldName(ISymbol fieldSymbol)
            {
                var name = fieldSymbol.Name.Trim('_');
                if (name.Length > 2 && char.IsLetter(name[0]) && name[1] == '_')
                {
                    name = name.Substring(2);
                }

                // Some .NET code uses "ts_" prefix for thread static
                if (name.Length > 3 && name.StartsWith("ts_", StringComparison.OrdinalIgnoreCase))
                {
                    name = name.Substring(3);
                }

                if (name.Length == 0)
                {
                    return fieldSymbol.Name;
                }

                if (name.Length > 2 && char.IsUpper(name[0]) && char.IsLower(name[1]))
                {
                    name = char.ToLower(name[0]) + name.Substring(1);
                }

                if (fieldSymbol.IsStatic)
                {
                    // Check for ThreadStatic private fields.
                    if (fieldSymbol.GetAttributes().Any(a => a.AttributeClass.Name.Equals("ThreadStaticAttribute", StringComparison.Ordinal)))
                    {
                        return "t_" + name;
                    }
                    else
                    {
                        return "s_" + name;
                    }
                }

                return "_" + name;
            }
开发者ID:patricksadowski,项目名称:codeformatter,代码行数:39,代码来源:PrivateFieldNamingRule.cs

示例14: IsRemovable

 public static bool IsRemovable(ISymbol symbol, Accessibility maxAccessibility)
 {
     return symbol != null &&
         EffectiveAccessibility(symbol) <= maxAccessibility &&
         !symbol.IsImplicitlyDeclared &&
         !symbol.IsAbstract &&
         !symbol.IsVirtual &&
         !symbol.GetAttributes().Any() &&
         !symbol.ContainingType.IsInterface() &&
         !symbol.IsInterfaceImplementationOrMemberOverride();
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:11,代码来源:RemovableDeclarationCollector.cs

示例15: AnalyzeSymbol

        private void AnalyzeSymbol(Action<Diagnostic> reportDiagnostic, ISymbol symbol)
        {
            var attributes = symbol.GetAttributes();

            foreach (var attribute in attributes)
            {
                Analyze(reportDiagnostic, attribute);
            }
        }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:9,代码来源:AttributeStringLiteralsShouldParseCorrectly.cs


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