当前位置: 首页>>代码示例>>C#>>正文


C# ICommandService.GetCommandInfo方法代码示例

本文整理汇总了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)
                                + "определен, а метод запроса статуса - нет.");
                }
        }
开发者ID:permyakov,项目名称:janus,代码行数:87,代码来源:CommandTarget.cs


注:本文中的ICommandService.GetCommandInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。