コード例 #1
0
        private static IEnumerable <string> GetSupportedLanguages(TypeDefinition typeDef, PEModule peModule, Type attributeType, AttributeLanguagesFunc languagesFunc)
        {
            IEnumerable <string>?result = null;

            foreach (CustomAttributeHandle customAttrHandle in typeDef.GetCustomAttributes())
            {
                if (peModule.IsTargetAttribute(customAttrHandle, attributeType.Namespace !, attributeType.Name, ctor: out _))
                {
                    if (languagesFunc(peModule, customAttrHandle) is { } attributeSupportedLanguages)
                    {
                        if (result is null)
                        {
                            result = attributeSupportedLanguages;
                        }
                        else
                        {
                            // This is a slow path, but only occurs if a single type has multiple
                            // DiagnosticAnalyzerAttribute instances applied to it.
                            result = result.Concat(attributeSupportedLanguages);
                        }
                    }
                }
            }

            return(result ?? SpecializedCollections.EmptyEnumerable <string>());
        }
コード例 #2
0
        private static IEnumerable <string> GetSupportedLanguages(TypeDefinition typeDef, PEModule peModule, Type attributeType, AttributeLanguagesFunc languagesFunc)
        {
            var attributeLanguagesList = from customAttrHandle in typeDef.GetCustomAttributes()
                                         where peModule.IsTargetAttribute(customAttrHandle, attributeType.Namespace !, attributeType.Name, ctor: out _)
                                         let attributeSupportedLanguages = languagesFunc(peModule, customAttrHandle)
                                                                           where attributeSupportedLanguages != null
                                                                           select attributeSupportedLanguages;

            return(attributeLanguagesList.SelectMany(x => x));
        }
コード例 #3
0
 private static IEnumerable <string> GetSupportedLanguages(TypeDefinition typeDef, PEModule peModule, Type attributeType, AttributeLanguagesFunc languagesFunc)
 {
     foreach (CustomAttributeHandle customAttrHandle in typeDef.GetCustomAttributes())
     {
         if (peModule.IsTargetAttribute(customAttrHandle, attributeType.Namespace !, attributeType.Name, ctor: out _))
         {
             IEnumerable <string>?attributeSupportedLanguages = languagesFunc(peModule, customAttrHandle);
             if (attributeSupportedLanguages != null)
             {
                 foreach (string item in attributeSupportedLanguages)
                 {
                     yield return(item);
                 }
             }
         }
     }
 }
コード例 #4
0
 private static bool IsDiagnosticAnalyzerAttribute(PEModule peModule, CustomAttributeHandle customAttrHandle)
 {
     return(peModule.IsTargetAttribute(customAttrHandle, s_diagnosticAnalyzerAttributeNamespace, nameof(DiagnosticAnalyzerAttribute), out EntityHandle ctor));
 }
コード例 #5
0
 private static bool IsGeneratorAttribute(PEModule peModule, CustomAttributeHandle customAttrHandle)
 {
     return(peModule.IsTargetAttribute(customAttrHandle, s_generatorAttributeNamespace, nameof(GeneratorAttribute), ctor: out _));
 }
コード例 #6
0
        private static bool IsSourceGeneratorAttribute(PEModule peModule, CustomAttributeHandle customAttrHandle)
        {
            EntityHandle ctor;

            return(peModule.IsTargetAttribute(customAttrHandle, s_sourceGeneratorAttributeNamespace, nameof(SourceGeneratorAttribute), out ctor));
        }