Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions Source/Csla/NameValueListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public abstract class NameValueListBase<[DynamicallyAccessedMembers(DynamicallyA
ICloneable,
IDataPortalTarget,
IUseApplicationContext
where K: notnull
where V: notnull
{
/// <summary>
Expand All @@ -56,14 +55,10 @@ ApplicationContext IUseApplicationContext.ApplicationContext
/// specified key.
/// </summary>
/// <param name="key">Key value for which to retrieve a value.</param>
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
public V? Value(K key)
{
if(key is null)
throw new ArgumentNullException(nameof(key));

foreach (NameValuePair item in this)
if (item.Key.Equals(key))
if (KeysEqual(item.Key, key))
return item.Value;
return default(V);
}
Expand Down Expand Up @@ -91,14 +86,10 @@ ApplicationContext IUseApplicationContext.ApplicationContext
/// specified key.
/// </summary>
/// <param name="key">Key value for which to search.</param>
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
public bool ContainsKey(K key)
{
if (key is null)
throw new ArgumentNullException(nameof(key));

foreach (NameValuePair item in this)
if (item.Key.Equals(key))
if (KeysEqual(item.Key, key))
return true;
return false;
}
Expand Down Expand Up @@ -154,15 +145,11 @@ public bool ContainsValue(V value)
/// Key to search for in the list.
/// </param>
/// <returns>Item from the list.</returns>
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
public NameValuePair? GetItemByKey(K key)
{
if (key is null)
throw new ArgumentNullException(nameof(key));

foreach (NameValuePair item in this)
{
if (item != null && item.Key.Equals(key))
if (KeysEqual(item.Key, key))
{
return item;
}
Expand All @@ -171,6 +158,11 @@ public bool ContainsValue(V value)

}

private static bool KeysEqual(K key1, K key2)
{
return EqualityComparer<K>.Default.Equals(key1, key2);
}

#endregion

/// <summary>
Expand Down Expand Up @@ -227,11 +219,9 @@ public NameValuePair()
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
public NameValuePair(K key, V value)
{
if (key is null)
throw new ArgumentNullException(nameof(key));
if (value is null)
throw new ArgumentNullException(nameof(value));

Expand Down
13 changes: 13 additions & 0 deletions Source/tests/csla.netcore.test/Basic/NullableKeyValueList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Csla.Test.Basic;

/// <summary>
/// Example that a nullable key is now possible for <see cref="NameValueListBase{K,V}"/>.
/// </summary>
public class NullableKeyValueList : NameValueListBase<int?, string>
{
[Fetch]
private void Fetch()
{
// This class must be compilable.
}
}
Loading