internal Extensions(AnalyzerFileReference reference, AttributePredicate attributePredicate) { _reference = reference; _attributePredicate = attributePredicate; _lazyAllExtensions = default(ImmutableArray <TExtension>); _lazyExtensionsPerLanguage = ImmutableDictionary <string, ImmutableArray <TExtension> > .Empty; }
internal Extensions(AnalyzerFileReference reference, AttributePredicate attributePredicate, AttributeLanguagesFunc languagesFunc, bool allowNetFramework) { _reference = reference; _attributePredicate = attributePredicate; _languagesFunc = languagesFunc; _allowNetFramework = allowNetFramework; _lazyAllExtensions = default; _lazyExtensionsPerLanguage = ImmutableDictionary <string, ImmutableArray <TExtension> > .Empty; }
private static IEnumerable <string> GetSupportedLanguages(TypeDefinition typeDef, PEModule peModule, AttributePredicate attributePredicate) { IEnumerable <IEnumerable <string> > attributeLanguagesList = from customAttrHandle in typeDef.GetCustomAttributes() where attributePredicate(peModule, customAttrHandle) let attributeSupportedLanguages = GetSupportedLanguages(peModule, customAttrHandle) where attributeSupportedLanguages != null select attributeSupportedLanguages; return(attributeLanguagesList.SelectMany(x => x)); }
/// <summary> /// Opens the analyzer dll with the metadata reader and builds a map of language -> analyzer type names. /// </summary> /// <exception cref="BadImageFormatException">The PE image format is invalid.</exception> /// <exception cref="IOException">IO error reading the metadata.</exception> private static ImmutableDictionary <string, ImmutableHashSet <string> > GetAnalyzerTypeNameMap(string fullPath, AttributePredicate attributePredicate) { using (AssemblyMetadata assembly = AssemblyMetadata.CreateFromFile(fullPath)) { IEnumerable <IGrouping <string, string> > typeNameMap = from module in assembly.GetModules() from typeDefHandle in module.MetadataReader.TypeDefinitions let typeDef = module.MetadataReader.GetTypeDefinition(typeDefHandle) let typeName = GetFullyQualifiedTypeName(typeDef, module.Module) from supportedLanguage in GetSupportedLanguages(typeDef, module.Module, attributePredicate) group typeName by supportedLanguage; return(typeNameMap.ToImmutableDictionary(g => g.Key, g => g.ToImmutableHashSet())); } }
private static ImmutableDictionary <string, ImmutableHashSet <string> > GetAnalyzerTypeNameMap(string fullPath, AttributePredicate attributePredicate) { using (var assembly = AssemblyMetadata.CreateFromFile(fullPath)) { // This is longer than strictly necessary to avoid thrashing the GC with string allocations // in the call to GetFullyQualifiedTypeNames. Specifically, this checks for the presence of // supported languages prior to creating the type names. var typeNameMap = from module in assembly.GetModules() from typeDefHandle in module.MetadataReader.TypeDefinitions let typeDef = module.MetadataReader.GetTypeDefinition(typeDefHandle) let supportedLanguages = GetSupportedLanguages(typeDef, module.Module, attributePredicate) where supportedLanguages.Any() let typeName = GetFullyQualifiedTypeName(typeDef, module.Module) from supportedLanguage in supportedLanguages group typeName by supportedLanguage; return(typeNameMap.ToImmutableDictionary(g => g.Key, g => g.ToImmutableHashSet())); } }