/// <summary> /// Removes any watch on the specified <paramref name="section"/>. /// </summary> /// <param name="section">The section.</param> public static void UnWatch([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)) { return; } lock (watcher._sections) { watcher._sections.Remove(section); if (watcher._sections.Count > 0) { return; } watcher.Dispose(); } // 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 } }