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


C# Symbol.GetAttributes方法代码示例

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


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

示例1: CheckForAttributeWithArrayArgument

 private void CheckForAttributeWithArrayArgument(Symbol symbol)
 {
     System.Diagnostics.Debug.Assert(IsTrue(GetDeclaredOrInheritedCompliance(symbol)), "Only call on compliant symbols");
     CheckForAttributeWithArrayArgumentInternal(symbol.GetAttributes());
     if (symbol.Kind == SymbolKind.Method)
     {
         CheckForAttributeWithArrayArgumentInternal(((MethodSymbol)symbol).GetReturnTypeAttributes());
     }
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:9,代码来源:ClsComplianceChecker.cs

示例2: GetDeclaredCompliance

        /// <remarks>
        /// As in dev11, we ignore the fact that CLSCompliantAttribute is inherited (i.e. from the base type)
        /// (see CSemanticChecker::CheckSymForCLS).  This should only affect types where the syntactic parent
        /// and the inheritance parent disagree.
        /// </remarks>
        private bool? GetDeclaredCompliance(Symbol symbol, out Location attributeLocation)
        {
            attributeLocation = null;
            foreach (CSharpAttributeData data in symbol.GetAttributes())
            {
                // Check signature before HasErrors to avoid realizing symbols for other attributes.
                if (data.IsTargetAttribute(symbol, AttributeDescription.CLSCompliantAttribute))
                {
                    NamedTypeSymbol attributeClass = data.AttributeClass;
                    if ((object)attributeClass != null)
                    {
                        DiagnosticInfo info = attributeClass.GetUseSiteDiagnostic();
                        if (info != null)
                        {
                            Location location = symbol.Locations.IsEmpty ? NoLocation.Singleton : symbol.Locations[0];
                            _diagnostics.Enqueue(new CSDiagnostic(info, location));
                            if (info.Severity >= DiagnosticSeverity.Error)
                            {
                                continue;
                            }
                        }
                    }

                    if (!data.HasErrors)
                    {
                        if (!TryGetAttributeWarningLocation(data, out attributeLocation))
                        {
                            attributeLocation = null;
                        }

                        ImmutableArray<TypedConstant> args = data.CommonConstructorArguments;
                        System.Diagnostics.Debug.Assert(args.Length == 1, "We already checked the signature and HasErrors.");

                        // Duplicates are reported elsewhere - we only care about the first (error-free) occurrence.
                        return (bool)args[0].Value;
                    }
                }
            }

            return null;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:46,代码来源:ClsComplianceChecker.cs


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