diff --git a/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs b/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs
index 2013a9e25..57f2c8b7e 100644
--- a/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs
+++ b/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs
@@ -134,12 +134,16 @@ namespace Artemis.Core.DataModelExpansions
if (key.Contains('.'))
throw new ArtemisCoreException("The provided key contains an illegal character (.)");
if (_dynamicChildren.ContainsKey(key))
+ {
throw new ArtemisCoreException($"Cannot add a dynamic child with key '{key}' " +
"because the key is already in use on by another dynamic property this data model.");
+ }
if (GetType().GetProperty(key) != null)
+ {
throw new ArtemisCoreException($"Cannot add a dynamic child with key '{key}' " +
"because the key is already in use by a static property on this data model.");
+ }
// Make sure a name is on the attribute or funny things might happen
attribute.Name ??= key.Humanize();
@@ -155,7 +159,7 @@ namespace Artemis.Core.DataModelExpansions
OnDynamicDataModelAdded(new DynamicDataModelChildEventArgs(dynamicChild, key));
return dynamicChild;
}
-
+
///
/// Gets a previously added dynamic child by its key
///
@@ -208,7 +212,8 @@ namespace Artemis.Core.DataModelExpansions
/// The key of the dynamic child
///
/// When this method returns, the associated with the specified
- /// key, if the key is found; otherwise, . This parameter is passed uninitialized.
+ /// key, if the key is found and the type matches; otherwise, . This parameter is passed
+ /// uninitialized.
///
///
/// if the data model contains the dynamic child; otherwise
@@ -267,7 +272,9 @@ namespace Artemis.Core.DataModelExpansions
// Used a runtime by data model paths only
internal T? GetDynamicChildValue(string key)
{
- return TryGetDynamicChild(key, out DynamicChild? dynamicChild) ? dynamicChild.Value : default;
+ if (TryGetDynamicChild(key, out DynamicChild? dynamicChild) && dynamicChild.BaseValue != null)
+ return (T) dynamicChild.BaseValue;
+ return default;
}
#endregion