123 lines
4.2 KiB
C#
123 lines
4.2 KiB
C#
using System;
|
|
using JD.Serializers.Xml;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace JD.PropertyService
|
|
{
|
|
/// <summary>
|
|
/// Simple, lightweight properties, without hierarchy.
|
|
/// </summary>
|
|
public interface IProperties : IReadOnlyProperties, ICloneable
|
|
{
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Whether these properties are read-only.
|
|
/// </summary>
|
|
bool IsReadOnly { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the value of the property with the given <paramref name="key"/>.
|
|
/// If no property exists with that key, <see cref="string.Empty"/> is added and returned.
|
|
/// </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>
|
|
new string this[string key] { get; set; }
|
|
|
|
/// <summary>
|
|
/// Parent of these properties, if any.
|
|
/// </summary>
|
|
new IProperties Parent { get; }
|
|
|
|
/// <summary>
|
|
/// Root of these properties.
|
|
/// </summary>
|
|
new IProperties Root { get; }
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
#region Set
|
|
|
|
/// <summary>
|
|
/// Sets the value of the property with the given <paramref name="key"/>.
|
|
/// </summary>
|
|
/// <param name="key">Key of the property to set.</param>
|
|
/// <param name="value">Value of the property.</param>
|
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="key"/> or <paramref name="value"/> is null.</exception>
|
|
/// <exception cref="NotSupportedException">Thrown when <see cref="IsReadOnly"/> is true.</exception>
|
|
void Set<T>(string key, T value);
|
|
|
|
/// <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>
|
|
[CanBeNull]
|
|
new IProperties 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>
|
|
new IProperties CreateSubKey(string key, AccessContext mode);
|
|
|
|
#endregion
|
|
|
|
#region General
|
|
|
|
/// <summary>
|
|
/// Attempts to remove the property with the given <paramref name="key"/>.
|
|
/// </summary>
|
|
/// <param name="key">Name of the property to remove.</param>
|
|
/// <returns>True if the property existed and was removed. False if there is no property with the name.</returns>
|
|
bool Remove(string key);
|
|
|
|
/// <summary>
|
|
/// Clears all the properties. (Use with caution).
|
|
/// </summary>
|
|
void Clear();
|
|
|
|
/// <summary>
|
|
/// Returns a readonly wrapped over the properties.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IReadOnlyProperties AsReadOnly();
|
|
|
|
/// <summary>
|
|
/// ReadFromXml.
|
|
/// </summary>
|
|
void ReadFromXml(XmlSerializerReader serializer);
|
|
|
|
/// <summary>
|
|
/// WriteToXml
|
|
/// </summary>
|
|
/// <param name="serializer"></param>
|
|
void WriteToXml(XmlSerializerWriter serializer);
|
|
|
|
#endregion
|
|
|
|
#region Bulk Update
|
|
|
|
/// <summary>
|
|
/// Starts an update that does not trigger the changed event.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IDisposable BeginScopedUpdate();
|
|
|
|
/// <summary>
|
|
/// Ends a scoped update.
|
|
/// </summary>
|
|
void EndUpdate();
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|