Exemple #1
0
        /// <summary>
        /// Returns a new instance of <typeparamref name="TModule"/> with the given context and using the given services.
        /// </summary>
        /// <param name="context">The command context to be used in this module.</param>
        /// <param name="provider">The objects to pass to this module's constructor.</param>
        /// <param name="beforeExecute">Whether to run <see cref="ModuleBase{T}.BeforeExecute(CommandInfo)"/>.</param>
        public static TModule Create(TContext context, IServiceProvider provider, bool beforeExecute = true)
        {
            var parameters = ConstructorParameters.Select(x => provider.GetService(x.ParameterType)).ToArray();
            var module     = (TModule)Constructor.Invoke(parameters);

            Context.SetValue(module, context, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);
            if (beforeExecute)
            {
                BeforeExecute.Invoke(module, new object[] { null });
            }

            return(module);
        }
        public string GetConstructorString()
        {
            var args = string.Join(", ", ConstructorParameters.Select(x => "__" + x.Name + "__"));

            return($"{FullName}({args})");
        }
 public override string ToString() => "{ " + string.Join(", ", ConstructorParameters.Select(p => p.Key + ": " + p.Value)) + " }";