Skip to content

Commit

Permalink
[doc] Remove compiler generated methods + filter property accessor me…
Browse files Browse the repository at this point in the history
…thods with IsSpecialName instead of String.StartsWith
  • Loading branch information
Harvey1214 committed Nov 16, 2022
1 parent 74b0e44 commit 8aa6ea6
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Havit.Blazor.Components.Web.Bootstrap.Documentation.Model;
using LoxSmoke.DocXml;
using Microsoft.JSInterop;
Expand Down Expand Up @@ -29,9 +30,13 @@ public class ComponentApiDocModelBuilder : IComponentApiDocModelBuilder
"Dispose",
"DisposeAsync",
"SetParametersAsync",
"ChildContent",
"op_Equality",
"op_Inequality"
"ChildContent"
};

private static readonly List<Type> attributesForMethodFiltering = new()
{
typeof(JSInvokableAttribute),
typeof(CompilerGeneratedAttribute)
};

private const BindingFlags CommonBindingFlags = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
Expand Down Expand Up @@ -216,13 +221,22 @@ private void MapMethods(DocXmlReader reader, ComponentApiDocModel model)

private bool ShouldIncludeMethod(MethodInfo methodInfo)
{
if (methodInfo.GetCustomAttribute<JSInvokableAttribute>() is not null)
foreach (var attribute in attributesForMethodFiltering)
{
if (methodInfo.GetCustomAttribute(attribute) is not null)
{
return false;
}
}

// Check if the method is a property accessor, ...
if (methodInfo.IsSpecialName)
{
return false;
}

string name = methodInfo.Name;
if (name.StartsWith("set") || name.StartsWith("get") || name.Contains("Clone") || ignoredMethods.Contains(name))
if (ignoredMethods.Contains(name))
{
return false;
}
Expand Down

0 comments on commit 8aa6ea6

Please sign in to comment.