Skip to content

4015 change context to interfaces #4025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 14, 2024
65 changes: 8 additions & 57 deletions Source/Csla/Core/ContextDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ namespace Csla.Core
[Serializable]
public class ContextDictionary : ConcurrentDictionary<object, object>, IContextDictionary
{
/// <summary>
/// Get a value from the dictionary, or return null
/// if the key is not found in the dictionary.
/// </summary>
/// <param name="key">Key of value to get from dictionary.</param>
/// <inheritdoc cref="Csla.Core.IContextDictionary.GetValueOrNull(string)"/>
public object GetValueOrNull(string key)
{
if (ContainsKey(key))
Expand Down Expand Up @@ -77,47 +73,25 @@ void IMobileObject.SetChildren(SerializationInfo info, MobileFormatter formatter

#region IDictionary Members

/// <summary>
/// Gets a value indicating whether the System.Collections.IDictionary object is
/// read-only.
/// </summary>
///<returns>true if the System.Collections.IDictionary object is read-only; otherwise, false.</returns>
/// <inheritdoc cref="System.Collections.IDictionary.IsReadOnly"/>
public bool IsReadOnly
{
get => ((IDictionary)this).IsReadOnly;
}

/// <summary>
/// Gets a value indicating whether the System.Collections.IDictionary object has
/// a fixed size.
/// </summary>
/// <returns>true if the System.Collections.IDictionary object has a fixed size; otherwise, false.</returns>
/// <inheritdoc cref="System.Collections.IDictionary.IsFixedSize"/>
public bool IsFixedSize
{
get => ((IDictionary)this).IsFixedSize;
}

/// <summary>
/// Adds an element with the provided key and value to the System.Collections.IDictionary
/// object.
/// </summary>
/// <param name="key">The System.Object to use as the key of the element to add.</param>
/// <param name="value">The System.Object to use as the value of the element to add.</param>
/// <exception cref="System.ArgumentNullException">key is null.</exception>
/// <exception cref="System.ArgumentException">An element with the same key already exists in the System.Collections.IDictionary object.</exception>
/// <exception cref="System.NotSupportedException">The System.Collections.IDictionary is read-only. -or- The System.Collections.IDictionary has a fixed size.</exception>
/// <inheritdoc cref="System.Collections.IDictionary.Add(object, object?)"/>
public void Add(object key, object value)
{
((IDictionary)this).Add(key, value);
}

/// <summary>
/// Removes the element with the specified key from the System.Collections.IDictionary
/// object.
/// </summary>
/// <param name="key">The key of the element to remove.</param>
/// <exception cref="System.ArgumentNullException">key is null.</exception>
/// <exception cref="System.NotSupportedException">The System.Collections.IDictionary object is read-only. -or- The System.Collections.IDictionary has a fixed size.</exception>
/// <inheritdoc cref="System.Collections.IDictionary.Remove(object)"/>
public void Remove(object key)
{
((IDictionary)this).Remove(key);
Expand All @@ -127,42 +101,19 @@ public void Remove(object key)

#region ICollection Members

/// <summary>
/// Gets an object that can be used to synchronize access to the System.Collections.ICollection.
/// </summary>
/// <returns>An object that can be used to synchronize access to the System.Collections.ICollection.</returns>
/// <inheritdoc cref="System.Collections.ICollection.SyncRoot"/>
public object SyncRoot
{
get => ((IDictionary)this).SyncRoot;
}

/// <summary>
/// Gets a value indicating whether access to the System.Collections.ICollection
/// is synchronized (thread safe).
/// </summary>
///<returns>true if access to the System.Collections.ICollection is synchronized (thread safe); otherwise, false.</returns>
/// <inheritdoc cref="System.Collections.ICollection.IsSynchronized"/>
public bool IsSynchronized
{
get => ((ICollection)this).IsSynchronized;
}

/// <summary>
/// Copies the elements of the System.Collections.ICollection to an System.Array,
/// starting at a particular System.Array index.
/// </summary>
/// <param name="array">
/// The one-dimensional System.Array that is the destination of the elements copied
/// from System.Collections.ICollection. The System.Array must have zero-based indexing.
/// </param>
/// <param name="index">The zero-based index in array at which copying begins.</param>
/// <exception cref="System.ArgumentNullException">array is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">index is less than zero.</exception>
/// <exception cref="System.ArgumentException">
/// array is multidimensional. -or- The number of elements in the source System.Collections.ICollection
/// is greater than the available space from index to the end of the destination
/// array. -or- The type of the source System.Collections.ICollection cannot be cast
/// automatically to the type of the destination array.
/// </exception>
/// <inheritdoc cref="System.Collections.ICollection.CopyTo(Array, int)"/>
public void CopyTo(Array array, int index)
{
((ICollection)this).CopyTo(array, index);
Expand Down
122 changes: 9 additions & 113 deletions Source/Csla/Core/IContextDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,135 +19,31 @@ public interface IContextDictionary : IMobileObject, IDictionary, ICollection, I
/// <returns>The value associated with the specified key, or null if the key does not exist.</returns>
object GetValueOrNull(string key);

/// <summary>
/// Attempts to add the specified key and value to the ContextDictionary.
/// </summary>
/// <param name="key">The key of the element to add.</param>
/// <param name="value">The value of the element to add. The value can be null for reference types.</param>
/// <returns>
/// true if the key/value pair was added to the ContextDictionary
/// successfully; false if the key already exists.
/// </returns>
/// <exception cref="System.ArgumentNullException">key is null.</exception>
/// <exception cref="System.OverflowException">The dictionary already contains the maximum number of elements (System.Int32.MaxValue).</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.TryAdd(TKey, TValue)"/>
bool TryAdd(object key, object value);

/// <summary>
/// Determines whether the ContextDictionary contains
/// the specified key.
/// </summary>
/// <param name="key">The key to locate in the ContextDictionary.</param>
/// <returns>
/// true if the ContextDictionary contains an
/// element with the specified key; otherwise, false.
/// </returns>
/// <exception cref="System.ArgumentNullException">key is null.</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.ContainsKey(TKey)"/>
public bool ContainsKey(object key);

/// <summary>
/// Attempts to remove and return the value that has the specified key from the ContextDictionary.
/// </summary>
/// <param name="key">The key of the element to remove and return.</param>
/// <param name="value">
/// When this method returns, contains the object removed from the ContextDictionary,
/// or the default value of the TValue type if key does not exist.
/// </param>
/// <returns>true if the object was removed successfully; otherwise, false.</returns>
/// <exception cref="System.ArgumentNullException">key is null.</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.TryRemove(TKey, out TValue)"/>
public bool TryRemove(object key, out object value);

/// <summary>
/// Attempts to get the value associated with the specified key from the ContextDictionary.
/// </summary>
/// <param name="key">The key of the value to get.</param>
/// <param name="value">
/// When this method returns, contains the object from the ContextDictionary
/// that has the specified key, or the default value of the type if the operation
/// failed.
/// </param>
/// <returns>true if the key was found in the ContextDictionary; otherwise, false.</returns>
/// <exception cref="System.ArgumentNullException">key is null.</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.TryGetValue(TKey, out TValue)"/>
public bool TryGetValue(object key, out object value);

/// <summary>
/// Updates the value associated with key to newValue if the existing value with
/// key is equal to comparisonValue.
/// </summary>
/// <param name="key">The key of the value that is compared with comparisonValue and possibly replaced.</param>
/// <param name="newValue">
/// The value that replaces the value of the element that has the specified key if
/// the comparison results in equality.
/// </param>
/// <param name="comparisonValue">
/// The value that is compared with the value of the element that has the specified
/// key.
/// </param>
/// <returns>true if the value with key was equal to comparisonValue and was replaced with newValue; otherwise, false.</returns>
/// <exception cref="System.ArgumentNullException">key is null.</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.TryUpdate(TKey, TValue, TValue)"/>
bool TryUpdate(object key, object newValue, object comparisonValue);

/// <summary>
/// Adds a key/value pair to the ContextDictionary
/// by using the specified function if the key does not already exist. Returns the
/// new value, or the existing value if the key exists.
/// </summary>
/// <param name="key">The key of the element to add.</param>
/// <param name="valueFactory">The function used to generate a value for the key.</param>
/// <returns>
/// The value for the key. This will be either the existing value for the key if
/// the key is already in the dictionary, or the new value if the key was not in
/// the dictionary.
/// </returns>
/// <exception cref="System.ArgumentNullException">key or valueFactory is null.</exception>
/// <exception cref="System.OverflowException">The dictionary already contains the maximum number of elements (System.Int32.MaxValue).</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.GetOrAdd(TKey, Func{TKey, TValue})"/>
object GetOrAdd(object key, Func<object, object> valueFactory);

/// <summary>
/// Adds a key/value pair to the ContextDictionary
/// if the key does not already exist. Returns the new value, or the existing value
/// if the key exists.
/// </summary>
/// <param name="key">The key of the element to add.</param>
/// <param name="value">The value to be added, if the key does not already exist.</param>
/// <returns>
/// The value for the key. This will be either the existing value for the key if
/// the key is already in the dictionary, or the new value if the key was not in
/// the dictionary.
/// </returns>
/// <exception cref="System.ArgumentNullException">key or valueFactory is null.</exception>
/// <exception cref="System.OverflowException">The dictionary already contains the maximum number of elements (System.Int32.MaxValue).</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.GetOrAdd(TKey, TValue)"/>
public object GetOrAdd(object key, object value);

/// <summary>
/// Uses the specified functions to add a key/value pair to the ContextDictionary
/// if the key does not already exist, or to update a key/value pair in the ContextDictionary
/// if the key already exists.
/// </summary>
/// <param name="key">The key to be added or whose value should be updated.</param>
/// <param name="addValueFactory">The function used to generate a value for an absent key.</param>
/// <param name="updateValueFactory">The function used to generate a new value for an existing key based on the key's existing value.</param>
/// <returns>
/// The new value for the key. This will be either be the result of addValueFactory
/// (if the key was absent) or the result of updateValueFactory (if the key was present).
/// </returns>
/// <exception cref="System.ArgumentNullException">key, addValueFactory, or updateValueFactory is null.</exception>
/// <exception cref="System.OverflowException">The dictionary already contains the maximum number of elements (System.Int32.MaxValue).</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.AddOrUpdate(TKey, Func{TKey, TValue}, Func{TKey, TValue, TValue})"/>
public object AddOrUpdate(object key, Func<object, object> addValueFactory, Func<object, object, object> updateValueFactory);

/// <summary>
/// Adds a key/value pair to the ContextDictionary
/// if the key does not already exist, or updates a key/value pair in the ContextDictionary
/// by using the specified function if the key already exists.
/// </summary>
/// <param name="key">The key to be added or whose value should be updated.</param>
/// <param name="addValue">The value to be added for an absent key.</param>
/// <param name="updateValueFactory">The function used to generate a new value for an existing key based on the key's existing value.</param>
/// <returns>
/// The new value for the key. This will be either be addValue (if the key was absent)
/// or the result of updateValueFactory (if the key was present).
/// </returns>
/// <exception cref="System.ArgumentNullException">key or updateValueFactory is null.</exception>
/// <exception cref="System.OverflowException">The dictionary already contains the maximum number of elements (System.Int32.MaxValue).</exception>
/// <inheritdoc cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}.AddOrUpdate(TKey, TValue, Func{TKey, TValue, TValue})"/>
public object AddOrUpdate(object key, object addValue, Func<object, object, object> updateValueFactory);
}
}
Loading