diff --git a/Source/Csla/NameValueListBase.cs b/Source/Csla/NameValueListBase.cs
index ad2b883e3f..7815f772ca 100644
--- a/Source/Csla/NameValueListBase.cs
+++ b/Source/Csla/NameValueListBase.cs
@@ -30,7 +30,6 @@ public abstract class NameValueListBase<[DynamicallyAccessedMembers(DynamicallyA
ICloneable,
IDataPortalTarget,
IUseApplicationContext
- where K: notnull
where V: notnull
{
///
@@ -56,14 +55,10 @@ ApplicationContext IUseApplicationContext.ApplicationContext
/// specified key.
///
/// Key value for which to retrieve a value.
- /// is .
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);
}
@@ -91,14 +86,10 @@ ApplicationContext IUseApplicationContext.ApplicationContext
/// specified key.
///
/// Key value for which to search.
- /// is .
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;
}
@@ -154,15 +145,11 @@ public bool ContainsValue(V value)
/// Key to search for in the list.
///
/// Item from the list.
- /// is .
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;
}
@@ -171,6 +158,11 @@ public bool ContainsValue(V value)
}
+ private static bool KeysEqual(K key1, K key2)
+ {
+ return EqualityComparer.Default.Equals(key1, key2);
+ }
+
#endregion
///
@@ -227,11 +219,9 @@ public NameValuePair()
///
/// The key.
/// The value.
- /// is .
+ /// is .
public NameValuePair(K key, V value)
{
- if (key is null)
- throw new ArgumentNullException(nameof(key));
if (value is null)
throw new ArgumentNullException(nameof(value));
diff --git a/Source/tests/csla.netcore.test/Basic/NullableKeyValueList.cs b/Source/tests/csla.netcore.test/Basic/NullableKeyValueList.cs
new file mode 100644
index 0000000000..c47eae73cb
--- /dev/null
+++ b/Source/tests/csla.netcore.test/Basic/NullableKeyValueList.cs
@@ -0,0 +1,13 @@
+namespace Csla.Test.Basic;
+
+///
+/// Example that a nullable key is now possible for .
+///
+public class NullableKeyValueList : NameValueListBase
+{
+ [Fetch]
+ private void Fetch()
+ {
+ // This class must be compilable.
+ }
+}
\ No newline at end of file