public static IReadOnlyConfigPropertyBase GetOrAddProperty([NotNull] IReadOnlyConfigPropertyBase property) { if (property is null) { throw new ArgumentNullException(nameof(property)); } IPropertyConfigBase config = property.Config; if (config is null) { throw new ArgumentException(@"Cannot add property without config", nameof(property)); } String path = property.Path; if (path is null) { throw new ArgumentException(@"Cannot add property without path", nameof(property)); } lock (Properties) { return(Properties.GetOrAdd(config, CreatePropertyMap).GetOrAdd(path, property)); } }
private static IConfigProperty <T> GetOrAddProperty <T>([NotNull] IPropertyConfigBase config, [NotNull] String key, [NotNull] IEnumerable <String> sections, [NotNull] Func <IConfigPropertyBase> factory) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (key is null) { throw new ArgumentNullException(nameof(key)); } if (sections is null) { throw new ArgumentNullException(nameof(sections)); } if (factory is null) { throw new ArgumentNullException(nameof(factory)); } String path = ConfigPropertyBase.GetPath(key, sections); if (ConfigPropertyObserver.GetOrAddProperty(config, path, factory) is IConfigProperty <T> result) { return(result); } throw new ArgumentException(@$ "Config already contains another property with same path '{path}' and different generic type.", nameof(sections)); }
public static void ForEachProperty([NotNull] IPropertyConfigBase config, [NotNull] Action <IReadOnlyConfigPropertyBase> action) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (action is null) { throw new ArgumentNullException(nameof(action)); } lock (Properties) { if (!Properties.TryGetValue(config, out IIndexMap <String, IReadOnlyConfigPropertyBase> dictionary)) { return; } foreach (IReadOnlyConfigPropertyBase value in dictionary.Values) { action(value); } } }
protected ConfigPropertyBase(IPropertyConfigBase config, [NotNull] String key, ICryptKey cryptKey, ConfigPropertyOptions options, IEnumerable <String> sections) { Config = config; Key = key ?? throw new ArgumentNullException(nameof(key)); CryptKey = cryptKey; Sections = sections.AsIImmutableList(); Options = options; }
public static Boolean ClearProperties([NotNull] IPropertyConfigBase config) { if (config is null) { throw new ArgumentNullException(nameof(config)); } lock (Properties) { return(Properties.Remove(config)); } }
public static IEnumerable <IReadOnlyConfigPropertyBase>?GetProperties([NotNull] IPropertyConfigBase config) { if (config is null) { throw new ArgumentNullException(nameof(config)); } lock (Properties) { return(Properties.TryGetValue(config, out IIndexMap <String, IReadOnlyConfigPropertyBase> dictionary) ? dictionary?.Values : null); } }
public static Boolean RemoveProperty([NotNull] IPropertyConfigBase config, [NotNull] IReadOnlyConfigPropertyBase property) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (property is null) { throw new ArgumentNullException(nameof(property)); } ThrowIfPropertyNotLinkedTo(config, property); return(RemoveProperty(property)); }
public static void ThrowIfPropertyNotLinkedTo([NotNull] IPropertyConfigBase config, [NotNull] IReadOnlyConfigPropertyBase property) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (property is null) { throw new ArgumentNullException(nameof(property)); } if (!IsLinkedTo(config, property)) { throw new InvalidOperationException("Property not linked to this config"); } }
public static Boolean IsLinkedTo([NotNull] IPropertyConfigBase config, [NotNull] IReadOnlyConfigPropertyBase property) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (property is null) { throw new ArgumentNullException(nameof(property)); } lock (Properties) { return(Properties.TryGetValue(config, out IIndexMap <String, IReadOnlyConfigPropertyBase> map) && map.ContainsValue(property)); } }
public static Boolean Contains([NotNull] IPropertyConfigBase config, [NotNull] String path) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (path is null) { throw new ArgumentNullException(nameof(path)); } lock (Properties) { return(Properties.TryGetValue(config, out IIndexMap <String, IReadOnlyConfigPropertyBase> properties) && properties.ContainsKey(path)); } }
public static IReadOnlyConfigPropertyBase GetOrAddProperty([NotNull] IPropertyConfigBase config, [NotNull] String path, [NotNull] Func <IReadOnlyConfigPropertyBase> factory) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (path is null) { throw new ArgumentNullException(nameof(path)); } if (factory is null) { throw new ArgumentNullException(nameof(factory)); } lock (Properties) { return(Properties.GetOrAdd(config, CreatePropertyMap).GetOrAdd(path, factory)); } }