- Refactoring code duplication in DefaultOrchardCommandHandler.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-04-06 16:51:20 -07:00
parent a6029ec425
commit 16782bd359

View File

@@ -47,22 +47,12 @@ namespace Orchard.Commands {
foreach (MethodInfo methodInfo in GetType().GetMethods()) {
if (String.Equals(methodInfo.Name, context.Command, StringComparison.OrdinalIgnoreCase)) {
CheckMethodForSwitches(methodInfo, context.Switches);
object[] invokeParameters = GetInvokeParametersForMethod(methodInfo, context.Arguments ?? new string[]{});
if (invokeParameters != null) {
context.Output = (string) methodInfo.Invoke(this, invokeParameters);
return;
}
if (TryInvokeCommand(methodInfo, context)) return;
}
foreach (OrchardCommandAttribute commandAttribute in methodInfo.GetCustomAttributes(typeof(OrchardCommandAttribute), false)) {
if (String.Equals(commandAttribute.Command, context.Command, StringComparison.OrdinalIgnoreCase)) {
CheckMethodForSwitches(methodInfo, context.Switches);
object[] invokeParameters = GetInvokeParametersForMethod(methodInfo, context.Arguments ?? new string[]{});
if (invokeParameters != null) {
context.Output = (string) methodInfo.Invoke(this, invokeParameters);
return;
}
if (TryInvokeCommand(methodInfo, context)) return;
}
}
}
@@ -70,6 +60,16 @@ namespace Orchard.Commands {
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) {
List<object> invokeParameters = new List<object>();