/// <summary> /// Disposes the specified instance. /// </summary> /// <param name="disposing">Whether this is disposing or finalizing.</param> /// <remarks> /// <para><paramref name="disposing"/> indicates whether the method was invoked from the /// <see cref="IDisposable.Dispose"/> implementation or from the finalizer. The implementation should check the /// parameter before accessing other reference objects. Such objects should only be accessed when the method /// is called from the <see cref="IDisposable.Dispose"/> implementation (when the <paramref name="disposing"/> /// parameter is equal to <see langword="true"/>). If the method is invoked from the finalizer /// (disposing is false), other objects should not be accessed. The reason is that objects are finalized in an /// unpredictable order and so they, or any of their dependencies, might already have been finalized.</para> /// </remarks> // ReSharper disable once VirtualMemberNeverOverriden.Global protected virtual void Dispose(bool disposing) { IsDisposed = true; // ReSharper disable once ExceptionNotDocumented // If we're disposing the active configuration section, we want to reload the active configuration. Interlocked.CompareExchange(ref _active, null, (T)this); if (!disposing) { return; } ConfigurationFileWatcher.UnWatch(this); // ReSharper disable once ExceptionNotDocumented BufferedAction <string> action = Interlocked.Exchange(ref _changeAction, null); action?.Dispose(); }
/// <summary> /// Watches the specified <paramref name="section"/>. /// </summary> /// <param name="section">The section.</param> public static void Watch([NotNull] IInternalConfigurationSection section) { string filePath = section.FilePath; if (string.IsNullOrWhiteSpace(filePath)) { return; } lock (_watchers) { ConfigurationFileWatcher watcher; // ReSharper disable AssignNullToNotNullAttribute, PossibleNullReferenceException if (!_watchers.TryGetValue(filePath, out watcher)) { watcher = _watchers[filePath] = new ConfigurationFileWatcher(filePath); } lock (watcher._sections) watcher._sections.Add(section); // ReSharper restore AssignNullToNotNullAttribute, PossibleNullReferenceException } }
/// <summary> /// Watches the specified <paramref name="section"/>. /// </summary> /// <param name="section">The section.</param> public static void Watch([NotNull] IInternalConfigurationSection section) { string filePath = section.FilePath; if (string.IsNullOrWhiteSpace(filePath)) return; lock (_watchers) { ConfigurationFileWatcher watcher; // ReSharper disable AssignNullToNotNullAttribute, PossibleNullReferenceException if (!_watchers.TryGetValue(filePath, out watcher)) watcher = _watchers[filePath] = new ConfigurationFileWatcher(filePath); lock (watcher._sections) watcher._sections.Add(section); // ReSharper restore AssignNullToNotNullAttribute, PossibleNullReferenceException } }