예제 #1
0
        /// <summary>
        /// Returns the <see cref="CliMethod"/> for the provided <see cref="MethodInfo"/>, creating
        /// it if it does not already exist.
        /// </summary>
        /// <param name="info">The method info.</param>
        /// <returns>
        /// A new or existing <see cref="CliMethod"/> instance.
        /// </returns>
        private CliMethod GetMethod(MethodInfo info)
        {
            var name   = CliMethod.GetMethodName(info);
            var method = methods.FirstOrDefault(x => x.Name == name);

            if (method == null)
            {
                methods.Add(method = new CliMethod(this, info));
            }

            return(method);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CliParameters"/> class for the specified
        /// <see cref="CliMethod"/> and <see cref="MethodInfo"/> to map.
        /// </summary>
        /// <param name="method">The <see cref="CliMethod"/> instance.</param>
        /// <param name="info">The <see cref="MethodInfo"/> instance.</param>
        public CliParameters(CliMethod method, MethodInfo info)
        {
            this.method = method ?? throw new ArgumentNullException(nameof(method));
            this.info   = info ?? throw new ArgumentNullException(nameof(info));

            parameters = info
                         .GetParameters()
                         .Select(x => new Parameter {
                DefaultValue = x.DefaultValue, IsDefault = x.HasDefaultValue, Name = GetParameterName(x), Type = x.ParameterType
            })
                         .ToArray();

            if (info.IsDefined(typeof(ExtensionAttribute), false))
            {
                parameters[0].IsThis = true;
            }
        }