Skip to content

Commit

Permalink
fix: change ExtendedSymbolKind to flags enum
Browse files Browse the repository at this point in the history
  • Loading branch information
filzrev committed Jan 30, 2024
1 parent 455ee29 commit 3fc575b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Docfx.Dotnet/Filters/ConfigFilterRuleItemUnion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ConfigFilterRuleItem Rule
}

// If kind is not specified for exclude. Set `ExtendedSymbolKind.Type` as default kind.
Exclude.Kind ??= ExtendedSymbolKind.Type;
Exclude.Kind ??= ExtendedSymbolKind.Type | ExtendedSymbolKind.Member;

return Exclude;
}
Expand Down
35 changes: 21 additions & 14 deletions src/Docfx.Dotnet/Filters/ExtendedSymbolKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@

namespace Docfx.Dotnet;

[Flags]
internal enum ExtendedSymbolKind
{
Assembly = 0x100,
Namespace = 0x110,
Type = 0x120,
Class,
Struct,
Enum,
Interface,
Delegate,
Member = 0x200,
Event,
Field,
Method,
Property,
#pragma warning disable format
Assembly = 1 << 1,
Namespace = 1 << 2,
// Type
Class = 1 << 3,
Struct = 1 << 4,
Enum = 1 << 5,
Interface = 1 << 6,
Delegate = 1 << 7,
// Member
Event = 1 << 8,
Field = 1 << 9,
Method = 1 << 10,
Property = 1 << 11,
#pragma warning restore format

Type = Class | Struct | Enum | Interface | Delegate,
Member = Event | Field | Method | Property,
}


internal static class ExtendedSymbolKindHelper
{
public static bool Contains(this ExtendedSymbolKind kind, SymbolFilterData symbol)
Expand All @@ -30,6 +37,6 @@ public static bool Contains(this ExtendedSymbolKind kind, SymbolFilterData symbo
{
return false;
}
return (kind & k.Value) == kind;
return (kind & k.Value) > 0;
}
}
6 changes: 6 additions & 0 deletions test/Docfx.Dotnet.Tests/ApiFilterUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ public class NestedClass : Class1
Assert.Equal("Microsoft.DevDiv.SpecialCase.NestedClass", nestedClass.Name);
}

[Fact]
public void TestExtendedSymbolKindFlags()
{
Assert.True((ExtendedSymbolKind.Type | ExtendedSymbolKind.Member).Contains(new SymbolFilterData { Kind = ExtendedSymbolKind.Interface }));
}

private static MetadataItem Verify(string code, ExtractMetadataConfig config = null, DotnetApiOptions options = null)
{
var compilation = CompilationHelper.CreateCompilationFromCSharpCode(code, "test.dll");
Expand Down

0 comments on commit 3fc575b

Please sign in to comment.