Automation/Commands/CommandService.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using ComLib;


namespace ComLib.Automation
{
    /// <summary>
    /// Service that loads all the commands ( that have CommandAttribute ) on classes.
    /// This loads commands from multiple dlls that are supplied by the caller.
    /// </summary>
    public class CommandService : ExtensionService<CommandAttribute, Command>
    {
        private const string DefaultParamFormat =
                                     "Name: {0} " + "{newline}"
                                   + "Desc: {1} " + "{newline}"
                                   + "Type: {2} " + "{newline}"
                                   + "Req : {3} " + "{newline}"
                                   + "E.g.: {4} " + "{newline}";


        /// <summary>
        /// Initialize command service
        /// </summary>
        public CommandService()
        {
            _onLoadCompleteCallback = () => LoadAdditionalAttributes<CommandParameterAttribute>();
        }


        /// <summary>
        /// Gets the help text for the command name.
        /// </summary>
        /// <param name="commandName">Name of the command to get help on</param>
        /// <param name="newLine">New line to use, defaults to Environment.NewLine</param>
        /// <returns></returns>
        public string GetHelpOn(string commandName, string newLine = "")
        {
            var info = _lookup[commandName];

            // Determine newline.
            if (string.IsNullOrEmpty(newLine)) newLine = Environment.NewLine;
            string format = DefaultParamFormat.Replace("{newline}", newLine);

            string text = info.Attribute.Name + newLine;
            if (info.AdditionalAttributes != null && info.AdditionalAttributes.Count > 0)
            {
                // Sort them by order number
                var orderedParams = new List<CommandParameterAttribute>();
                foreach (var param in info.AdditionalAttributes)
                    orderedParams.Add(param as CommandParameterAttribute);

                orderedParams = orderedParams.OrderBy(p => p.OrderNum).ToList();

                foreach (CommandParameterAttribute param in orderedParams)
                {
后面还有 63 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。