private static bool IsBrowsingProhibitedByEditorBrowsableAttribute( ISymbol symbol, ImmutableArray <AttributeData> attributes, bool hideAdvancedMembers, Compilation compilation, IMethodSymbol constructor) { constructor = constructor ?? EditorBrowsableHelpers.GetSpecialEditorBrowsableAttributeConstructor(compilation); if (constructor == null) { return(false); } foreach (var attribute in attributes) { if (attribute.AttributeConstructor == constructor && attribute.ConstructorArguments.Length == 1 && attribute.ConstructorArguments.First().Value is int) { var state = (EditorBrowsableState)attribute.ConstructorArguments.First().Value; if (EditorBrowsableState.Never == state || (hideAdvancedMembers && EditorBrowsableState.Advanced == state)) { return(true); } } } return(false); }
/// <summary> /// First, remove symbols from the set if they are overridden by other symbols in the set. /// If a symbol is overridden only by symbols outside of the set, then it is not removed. /// This is useful for filtering out symbols that cannot be accessed in a given context due /// to the existence of overriding members. Second, remove remaining symbols that are /// unsupported (e.g. pointer types in VB) or not editor browsable based on the EditorBrowsable /// attribute. /// </summary> public static ImmutableArray <T> FilterToVisibleAndBrowsableSymbols <T>( this ImmutableArray <T> symbols, bool hideAdvancedMembers, Compilation compilation) where T : ISymbol { symbols = symbols.RemoveOverriddenSymbolsWithinSet(); // Since all symbols are from the same compilation, find the required attribute // constructors once and reuse. var editorBrowsableAttributeConstructor = EditorBrowsableHelpers.GetSpecialEditorBrowsableAttributeConstructor(compilation); var typeLibTypeAttributeConstructors = EditorBrowsableHelpers.GetSpecialTypeLibTypeAttributeConstructors(compilation); var typeLibFuncAttributeConstructors = EditorBrowsableHelpers.GetSpecialTypeLibFuncAttributeConstructors(compilation); var typeLibVarAttributeConstructors = EditorBrowsableHelpers.GetSpecialTypeLibVarAttributeConstructors(compilation); var hideModuleNameAttribute = compilation.HideModuleNameAttribute(); // PERF: HasUnsupportedMetadata may require recreating the syntax tree to get the base class, so first // check to see if we're referencing a symbol defined in source. Func <Location, bool> isSymbolDefinedInSource = l => l.IsInSource; return(symbols.WhereAsArray(s => (s.Locations.Any(isSymbolDefinedInSource) || !s.HasUnsupportedMetadata) && !s.IsDestructor() && s.IsEditorBrowsable( hideAdvancedMembers, compilation, editorBrowsableAttributeConstructor, typeLibTypeAttributeConstructors, typeLibFuncAttributeConstructors, typeLibVarAttributeConstructors, hideModuleNameAttribute))); }
private static bool IsBrowsingProhibitedByEditorBrowsableAttribute( ImmutableArray <AttributeData> attributes, bool hideAdvancedMembers, Compilation compilation, IMethodSymbol?constructor) { constructor ??= EditorBrowsableHelpers.GetSpecialEditorBrowsableAttributeConstructor(compilation); if (constructor == null) { return(false); } foreach (var attribute in attributes) { if (Equals(attribute.AttributeConstructor, constructor) && attribute.ConstructorArguments.Length == 1 && attribute.ConstructorArguments.First().Value is int) { #nullable disable // Should use unboxed value from previous 'is int' https://github.com/dotnet/roslyn/issues/39166 var state = (EditorBrowsableState)attribute.ConstructorArguments.First().Value; #nullable enable if (EditorBrowsableState.Never == state || (hideAdvancedMembers && EditorBrowsableState.Advanced == state)) { return(true); } }
private static void AddListItemsFromSymbols <TSymbol>( IEnumerable <TSymbol> symbols, Compilation compilation, ProjectId projectId, Func <TSymbol, ProjectId, bool, ObjectListItem> listItemCreator, ImmutableArray <ObjectListItem> .Builder builder) where TSymbol : class, ISymbol { var editorBrowsableAttributeConstructor = EditorBrowsableHelpers.GetSpecialEditorBrowsableAttributeConstructor(compilation); var typeLibFuncAttributeConstructors = EditorBrowsableHelpers.GetSpecialTypeLibFuncAttributeConstructors(compilation); var typeLibTypeAttributeConstructors = EditorBrowsableHelpers.GetSpecialTypeLibTypeAttributeConstructors(compilation); var typeLibVarAttributeConstructors = EditorBrowsableHelpers.GetSpecialTypeLibVarAttributeConstructors(compilation); foreach (var symbol in symbols) { if (!IncludeSymbol(symbol)) { continue; } var hideAdvancedMembers = false; var isHidden = !symbol.IsEditorBrowsable( hideAdvancedMembers, compilation, editorBrowsableAttributeConstructor, typeLibFuncAttributeConstructors, typeLibTypeAttributeConstructors, typeLibVarAttributeConstructors); builder.Add(listItemCreator(symbol, projectId, isHidden)); } }
private static bool IsBrowsingProhibitedByTypeLibVarAttribute( ISymbol symbol, ImmutableArray <AttributeData> attributes, Compilation compilation, List <IMethodSymbol> constructors) { return(IsBrowsingProhibitedByTypeLibAttributeWorker( symbol, attributes, constructors ?? EditorBrowsableHelpers.GetSpecialTypeLibVarAttributeConstructors(compilation), TypeLibVarFlagsFHidden)); }
private static bool IsBrowsingProhibitedByTypeLibFuncAttribute( ISymbol symbol, ImmutableArray <AttributeData> attributes, Compilation compilation, List <IMethodSymbol> constructors) { return(IsBrowsingProhibitedByTypeLibAttributeWorker( symbol, attributes, constructors ?? EditorBrowsableHelpers.GetSpecialTypeLibFuncAttributeConstructors(compilation), (int)System.Runtime.InteropServices.TypeLibFuncFlags.FHidden)); }