mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Simplify code to filter out special methods
--HG-- branch : dev
This commit is contained in:
@@ -58,6 +58,18 @@ namespace Orchard.Tests.Commands {
|
||||
private void Blah() {
|
||||
}
|
||||
|
||||
// no private method
|
||||
public static void Foo() {
|
||||
}
|
||||
|
||||
// no operator
|
||||
public static bool operator ==(PublicMethodsOnly a, PublicMethodsOnly b) {
|
||||
return false;
|
||||
}
|
||||
public static bool operator !=(PublicMethodsOnly a, PublicMethodsOnly b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Method() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,36 +10,15 @@ namespace Orchard.Commands {
|
||||
}
|
||||
|
||||
private IEnumerable<CommandDescriptor> CollectMethods(Type type) {
|
||||
var allMethods = type
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
|
||||
|
||||
var allAccessors = type
|
||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
|
||||
.SelectMany(p => p.GetAccessors());
|
||||
|
||||
var allEventMethods = type
|
||||
.GetEvents(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
|
||||
.SelectMany(e => GetEventMethods(e));
|
||||
|
||||
var methods = allMethods.Except(allAccessors).Except(allEventMethods);
|
||||
var methods = type
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
|
||||
.Where(m => !m.IsSpecialName);
|
||||
|
||||
foreach (var methodInfo in methods) {
|
||||
yield return BuildMethod(methodInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<MethodInfo> GetEventMethods(EventInfo info) {
|
||||
if (info.GetAddMethod() != null)
|
||||
yield return info.GetAddMethod();
|
||||
if (info.GetRaiseMethod() != null)
|
||||
yield return info.GetRaiseMethod();
|
||||
if (info.GetRemoveMethod() != null)
|
||||
yield return info.GetRemoveMethod();
|
||||
|
||||
foreach(var other in info.GetOtherMethods())
|
||||
yield return other;
|
||||
}
|
||||
|
||||
private CommandDescriptor BuildMethod(MethodInfo methodInfo) {
|
||||
return new CommandDescriptor {
|
||||
Name = GetCommandName(methodInfo),
|
||||
|
||||
Reference in New Issue
Block a user