Exemplo n.º 1
0
 /// <summary>
 /// Initializes a <see cref="Command"/>
 /// </summary>
 /// <param name="method"></param>
 /// <param name="instance"></param>
 internal CompiledCommand(MethodInfo method, object instance)
     : base(names: ValidateMethodAndGetCommandNames(method),
            description: method.GetCustomAttribute <HelpDescriptionAttribute>()?.Description ?? "No description was provided for this command.",
            isRaw: method.IsDefined(typeof(RawInputAttribute)),
            arguments: GetArguments(method),
            examples: method.GetCustomAttributes <HelpExampleAttribute>().Select(ex => ex.Example))
 {
     Method   = method;
     Instance = instance;
     CompiledCommandDelegate = CommandCompiler.Compile(method, instance);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new compiled command instance compiling the conversion method.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="instance"></param>
        /// <param name="names"></param>
        /// <param name="description"></param>
        /// <param name="isRaw"></param>
        /// <param name="examples"></param>
        internal CompiledCommand(MethodInfo method,
                                 object instance,
                                 IEnumerable <string> names,
                                 string description            = "No description provided for this command.",
                                 bool isRaw                    = false,
                                 IEnumerable <string> examples = null) : base(names, description, isRaw, GetArgumentsHelpData(method), examples)
        {
            if (names == null)
            {
                throw new ArgumentNullException(nameof(names));
            }

            if (!names.Any())
            {
                throw new ArgumentException("No names provided", nameof(names));
            }

            Method   = method ?? throw new ArgumentNullException(nameof(method));
            Instance = instance;
            CompiledCommandDelegate = CommandCompiler.Compile(method, instance);
        }