Esempio n. 1
0
        private PluginPath(string[] segments, Reflection.MemberToken[] members)
        {
            _segments = segments ?? new string[0];
            _members  = members ?? new Reflection.MemberToken[0];
            _anchor   = IO.PathAnchor.None;
            _path     = string.Empty;

            if (segments.Length > 0)
            {
                switch (segments[0])
                {
                case "":
                    _anchor = IO.PathAnchor.Root;
                    break;

                case ".":
                    _anchor = IO.PathAnchor.Current;
                    break;

                case "..":
                    _anchor = IO.PathAnchor.Parent;
                    break;
                }

                if (segments.Length == 1 && segments[0].Length == 0)
                {
                    _path = "/";
                }
                else
                {
                    _path = string.Join("/", segments);
                }
            }
        }
Esempio n. 2
0
        public CommandExpression(Zongsoft.IO.PathAnchor anchor, string name, string path, IDictionary <string, string> options, params string[] arguments)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            //修缮传入的路径参数值
            path = path.Trim('/', ' ', '\t', '\r', '\n');

            _anchor = anchor;
            _name   = name.Trim();

            switch (anchor)
            {
            case IO.PathAnchor.Root:
                if (string.IsNullOrEmpty(path))
                {
                    _path = "/";
                }
                else
                {
                    _path = "/" + path + "/";
                }
                break;

            case IO.PathAnchor.Current:
                if (string.IsNullOrEmpty(path))
                {
                    _path = "./";
                }
                else
                {
                    _path = "./" + path + "/";
                }
                break;

            case IO.PathAnchor.Parent:
                if (string.IsNullOrEmpty(path))
                {
                    _path = "../";
                }
                else
                {
                    _path = "../" + path + "/";
                }
                break;

            default:
                if (string.IsNullOrEmpty(path))
                {
                    _path = string.Empty;
                }
                else
                {
                    _path = path + "/";
                }
                break;
            }

            _fullPath = _path + _name;

            if (options == null || options.Count == 0)
            {
                _options = new CommandOptionCollection();
            }
            else
            {
                _options = new CommandOptionCollection(options);
            }

            _arguments = arguments ?? new string[0];
        }