本文整理汇总了C#中ICommandService.GetCommandInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ICommandService.GetCommandInfo方法的具体用法?C# ICommandService.GetCommandInfo怎么用?C# ICommandService.GetCommandInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommandService
的用法示例。
在下文中一共展示了ICommandService.GetCommandInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommandTarget
protected CommandTarget([NotNull] IServiceProvider serviceProvider)
{
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
_commandService = serviceProvider.GetRequiredService<ICommandService>();
var subscribeCommands = new List<string>();
foreach (var method in
GetType().GetMethods(
BindingFlags.Instance
| BindingFlags.Static
| BindingFlags.Public
| BindingFlags.NonPublic))
{
var attributes = Attribute.GetCustomAttributes(method);
if (attributes.Length == 0)
continue;
foreach (var attribute in attributes)
{
var executorAttribute = attribute as CommandExecutorAttribute;
if (executorAttribute != null)
{
var commandName = executorAttribute.CommandName;
if (_executeMethods.ContainsKey(commandName))
throw new ApplicationException(
"Метод выполнения команды '{0}' определен несколько раз."
.FormatStr(commandName));
_executeMethods[commandName] =
CreateExecuteMethod(_commandService.GetCommandInfo(commandName), method);
continue;
}
var statusAttribute = attribute as CommandStatusGetterAttribute;
if (statusAttribute != null)
{
var commandName = statusAttribute.CommandName;
if (_statusMethods.ContainsKey(commandName))
throw new ApplicationException(
"Метод запроса статуса команды '{0}' определен несколько раз."
.FormatStr(commandName));
_statusMethods[commandName] =
CreateStatusMethod(_commandService.GetCommandInfo(commandName), method);
continue;
}
var subscribeAttr = attribute as CommandStatusSubscriberAttribute;
if (subscribeAttr != null)
subscribeCommands.Add(subscribeAttr.CommandName);
}
if (subscribeCommands.Count > 0)
{
_subscribeMethods.Add(CreateSubscribeMethod(method, subscribeCommands.ToArray()));
subscribeCommands.Clear();
}
}
foreach (var statusGetter in _statusMethods.Values)
if (!_executeMethods.ContainsKey(statusGetter.CommandInfo.Name))
throw new ApplicationException(
"Метод запроса статуса команды '{0}' определен, а метод выполнения - нет."
.FormatStr(statusGetter.CommandInfo.Name));
foreach (var subscribeMethod in _subscribeMethods)
foreach (var commandName in subscribeMethod.CommandNames)
{
if (!_executeMethods.ContainsKey(commandName))
throw new ApplicationException(
"Метод подписки на оповещения о смене статуса статуса '{0}' команды '{1}' "
.FormatStr(MethodBase.GetMethodFromHandle(subscribeMethod.MethodHandle).Name, commandName)
+ "определен, а метод выполнения - нет.");
if (!_statusMethods.ContainsKey(commandName))
throw new ApplicationException(
"Метод подписки на оповещения о смене статуса статуса '{0}' команды '{1}' "
.FormatStr(MethodBase.GetMethodFromHandle(subscribeMethod.MethodHandle).Name, commandName)
+ "определен, а метод запроса статуса - нет.");
}
}