示例#1
0
 /// <inheritdoc />
 protected ToolContextBase(TOptions options, IProgressVisualizerFactory progressVisualizerFactory, Action <string> logLine, Action <string> log)
 {
     Options = options ?? throw new ArgumentNullException(nameof(options));
     ProgressVisualizerFactory = progressVisualizerFactory ?? throw new ArgumentNullException(nameof(progressVisualizerFactory));
     _logLine = logLine ?? throw new ArgumentNullException(nameof(logLine));
     _log     = log ?? throw new ArgumentNullException(nameof(log));
 }
        protected virtual bool TryCreateContextInternal <T>(T options, IProgressVisualizerFactory progressVisualizerFactory,
                                                            Action <string> lineLogger, Action <string> contentLogger, out IToolContext <IToolOptions> context) where T : class, IToolOptions
        {
            context = null;
            if (options is T generatorOptions)
            {
                var genericBaseType = typeof(GenericContext <>);
                var genericType     = genericBaseType.MakeGenericType(options.GetType());

                try
                {
                    context = Activator.CreateInstance(genericType,
                                                       new object[] { generatorOptions, progressVisualizerFactory, lineLogger, contentLogger }) as IToolContext <IToolOptions>;

                    return(context != null);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }

            return(false);
        }
示例#3
0
 /// <inheritdoc />
 public GenericContext(TOptions options, IProgressVisualizerFactory progressVisualizerFactory,
                       Action <string> logLine, Action <string> log) : base(options, progressVisualizerFactory, logLine, log)
 {
 }