130 lines
No EOL
5.4 KiB
C#
130 lines
No EOL
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace JD.PropertyService
|
|
{
|
|
public interface IReadOnlyProperties : IReadOnlyDictionary<string, object>
|
|
{
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Value Keys.
|
|
/// </summary>
|
|
IEnumerable<string> ValueKeys { get; }
|
|
|
|
/// <summary>
|
|
/// Parent of these properties, if any.
|
|
/// </summary>
|
|
IReadOnlyProperties Parent { get; }
|
|
|
|
/// <summary>
|
|
/// Root of these properties.
|
|
/// </summary>
|
|
IReadOnlyProperties Root { get; }
|
|
|
|
/// <summary>
|
|
/// Keys for which a sub properties is associated.
|
|
/// </summary>
|
|
IEnumerable<string> SubKeys { get; }
|
|
|
|
#endregion
|
|
|
|
#region Get
|
|
|
|
/// <summary>
|
|
/// Gets the value of the property with the given <paramref name="key"/>.
|
|
/// If no property exists with that key, <paramref name="defaultValue"/> is added and returned.
|
|
/// </summary>
|
|
/// <param name="key">Key of the property to get.</param>
|
|
/// <param name="defaultValue">Default value to use is the property is not found.</param>
|
|
/// <param name="options">Options to use to retrieve the property.</param>
|
|
/// <returns>The value of the property.</returns>
|
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="key"/> is null.</exception>
|
|
T Get<T>(string key, T defaultValue, PropertyOptions options);
|
|
|
|
/// <summary>
|
|
/// Gets the value of the property with the given <paramref name="key"/>.
|
|
/// If no property exists with that key, <paramref name="defaultValue"/> is added and returned.
|
|
/// </summary>
|
|
/// <param name="key">Key of the property to get.</param>
|
|
/// <param name="defaultValue">Default value to use is the property is not found.</param>
|
|
/// <returns>The value of the property.</returns>
|
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="key"/> is null.</exception>
|
|
T Get<T>(string key, T defaultValue);
|
|
|
|
/// <summary>
|
|
/// Gets the value of the property with the given <paramref name="key"/>.
|
|
/// </summary>
|
|
/// <param name="key">Key of the property to get.</param>
|
|
/// <returns>The value of the property.</returns>
|
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="key"/> is null.</exception>
|
|
/// <exception cref="KeyNotFoundException">Thrown if the <paramref name="key"/> doesn't exist in these properties.</exception>
|
|
T Get<T>(string key);
|
|
|
|
/// <summary>
|
|
/// Gets sub-properties with the given <paramref name="key"/>.
|
|
/// </summary>
|
|
/// <param name="key">Key to get the properties for.</param>
|
|
/// <returns>The sub-properties for the given <paramref name="key"/> or null if not found.</returns>
|
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="key"/> is empty.</exception>
|
|
IReadOnlyProperties GetSubKey(string key);
|
|
|
|
/// <summary>
|
|
/// Creates sub-properties with the given <paramref name="key"/> or opens existing one.
|
|
/// </summary>
|
|
/// <param name="key">Key to get the properties for.</param>
|
|
/// <param name="mode"></param>
|
|
/// <returns>The sub-properties for the given <paramref name="key"/> or null if could not create a key (in a read-only instance for example).</returns>
|
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="key"/> is empty.</exception>
|
|
IReadOnlyProperties CreateSubKey(string key, AccessContext mode);
|
|
|
|
/// <summary>
|
|
/// Attempts to remove the sub-key with the given <paramref name="key"/>.
|
|
/// </summary>
|
|
/// <param name="key">Name of the sub-key to remove.</param>
|
|
/// <param name="mode">PropertyChanged event is called when removed if the mode is in write.</param>
|
|
/// <returns>True if the sub-key existed and was removed. False if there is no sub-key with the name.</returns>
|
|
bool RemoveSubKey(string key, AccessContext mode);
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Adds the values to the target.
|
|
/// </summary>
|
|
void CopyTo(IProperties target);
|
|
|
|
/// <summary>
|
|
/// Whether the properties contain the specified value.
|
|
/// </summary>
|
|
/// <param name="key">Name of the property to check for.</param>
|
|
/// <returns>True if the value exists. False otherwise.</returns>
|
|
bool Contains(string key);
|
|
|
|
/// <summary>
|
|
/// Saves the properties.
|
|
/// </summary>
|
|
/// <returns>True if the properties were saved (false if the save failed or if not implemented).</returns>
|
|
/// <remarks>Properties can be saved periodically, calling save ensure the last modifications will be there even if the application crashes</remarks>
|
|
bool Save();
|
|
|
|
/// <summary>
|
|
/// True if the content of the properties is equal to the content of the other collection.
|
|
/// </summary>
|
|
/// <param name="others"></param>
|
|
/// <returns></returns>
|
|
bool IsEqualTo(IReadOnlyProperties others);
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
/// <summary>
|
|
/// Triggered when the value of a property changes.
|
|
/// </summary>
|
|
event EventHandler<PropertyChangedEventArgs> PropertyChanged;
|
|
|
|
#endregion
|
|
}
|
|
} |