/// <summary> /// Gets the options for an object. /// </summary> /// <param name="target">The object.</param> /// <returns>The complete options that apply to the specified object.</returns> public HConsoleTargetOptions Get(object target) { if (_targetConfigs.TryGetValue(target, out var config)) { config = config.Clone(); } else { config = new HConsoleTargetOptions(); } var type = target.GetType(); while (type != null && !config.IsComplete) { if (_typeConfigs.TryGetValue(type, out var c)) { config = config.Merge(c); } type = type.BaseType; } if (!config.IsComplete) { config = config.Merge(HConsoleTargetOptions.Default); } return(config); }
/// <summary> /// Sets the options for an object type. /// </summary> /// <typeparam name="TObject">The type of the object.</typeparam> /// <param name="configure">An action to configure the options.</param> /// <returns>The console options.</returns> public HConsoleOptions Set <TObject>(Action <HConsoleTargetOptions> configure) { #if HZ_CONSOLE if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var type = typeof(TObject); if (!_typeConfigs.TryGetValue(type, out var info)) { info = _typeConfigs[type] = new HConsoleTargetOptions(); } configure(info); #endif return(this); }
/// <summary> /// Clones these options. /// </summary> /// <returns>A clone of these options.</returns> public HConsoleTargetOptions Clone() { var clone = new HConsoleTargetOptions(); if (_hasIndent) { clone.SetIndent(Indent); } if (_hasPrefix) { clone.SetPrefix(Prefix); } if (_hasLevel) { clone.SetLevel(Level); } return(clone); }
/// <summary> /// Sets the options for a specific object. /// </summary> /// <param name="target">The object.</param> /// <param name="configure">An action to configure the options.</param> /// <returns>The console options.</returns> public HConsoleOptions Set(object target, Action <HConsoleTargetOptions> configure) { #if HZ_CONSOLE if (target == null) { throw new ArgumentNullException(nameof(target)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } if (!_targetConfigs.TryGetValue(target, out var info)) { info = _targetConfigs[target] = new HConsoleTargetOptions(); } configure(info); #endif return(this); }
/// <summary> /// Clones these options. /// </summary> /// <returns>A clone of these options.</returns> public HConsoleTargetOptions Clone() { var clone = new HConsoleTargetOptions(_options); if (_hasIndent) { clone.SetIndent(Indent); } if (_hasPrefix) { clone.SetPrefix(Prefix); } if (_hasLevel) { clone.SetLevel(Level); } if (_hasTimeStamp) { clone.EnableTimeStamp(TimeStampEnabled, TimeStampOrigin); } return(clone); }