mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
- Refactoring code duplication in DefaultOrchardCommandHandler.
--HG-- branch : dev
This commit is contained in:
@@ -47,22 +47,12 @@ namespace Orchard.Commands {
|
|||||||
|
|
||||||
foreach (MethodInfo methodInfo in GetType().GetMethods()) {
|
foreach (MethodInfo methodInfo in GetType().GetMethods()) {
|
||||||
if (String.Equals(methodInfo.Name, context.Command, StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(methodInfo.Name, context.Command, StringComparison.OrdinalIgnoreCase)) {
|
||||||
CheckMethodForSwitches(methodInfo, context.Switches);
|
if (TryInvokeCommand(methodInfo, context)) return;
|
||||||
object[] invokeParameters = GetInvokeParametersForMethod(methodInfo, context.Arguments ?? new string[]{});
|
|
||||||
if (invokeParameters != null) {
|
|
||||||
context.Output = (string) methodInfo.Invoke(this, invokeParameters);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (OrchardCommandAttribute commandAttribute in methodInfo.GetCustomAttributes(typeof(OrchardCommandAttribute), false)) {
|
foreach (OrchardCommandAttribute commandAttribute in methodInfo.GetCustomAttributes(typeof(OrchardCommandAttribute), false)) {
|
||||||
if (String.Equals(commandAttribute.Command, context.Command, StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(commandAttribute.Command, context.Command, StringComparison.OrdinalIgnoreCase)) {
|
||||||
CheckMethodForSwitches(methodInfo, context.Switches);
|
if (TryInvokeCommand(methodInfo, context)) return;
|
||||||
object[] invokeParameters = GetInvokeParametersForMethod(methodInfo, context.Arguments ?? new string[]{});
|
|
||||||
if (invokeParameters != null) {
|
|
||||||
context.Output = (string) methodInfo.Invoke(this, invokeParameters);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,6 +60,16 @@ namespace Orchard.Commands {
|
|||||||
throw new InvalidOperationException(T("Command : ") + context.Command + T(" was not found "));
|
throw new InvalidOperationException(T("Command : ") + context.Command + T(" was not found "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool TryInvokeCommand(MethodInfo methodInfo, CommandContext context) {
|
||||||
|
CheckMethodForSwitches(methodInfo, context.Switches);
|
||||||
|
object[] invokeParameters = GetInvokeParametersForMethod(methodInfo, context.Arguments ?? new string[] { });
|
||||||
|
if (invokeParameters != null) {
|
||||||
|
context.Output = (string)methodInfo.Invoke(this, invokeParameters);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, string[] arguments) {
|
private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, string[] arguments) {
|
||||||
List<object> invokeParameters = new List<object>();
|
List<object> invokeParameters = new List<object>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user