mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Dynamic data model - Removed DataModel constraint
Dynamic data model - Added ability to provide custom description attribute
This commit is contained in:
1 parent
5e345fed7c
commit
8cba36f5d4
4 files changed
+182
-96
No files matched your search
@@ -15,6 +15,8 @@ namespace Artemis.Core
|
||||
{
|
||||
private Expression<Func<object, object>>? _accessorLambda;
|
||||
private DataModel? _dynamicDataModel;
|
||||
private Type _dynamicDataModelType;
|
||||
private DataModelPropertyAttribute _dynamicDataModelAttribute;
|
||||
|
||||
internal DataModelPathSegment(DataModelPath dataModelPath, string identifier, string path)
|
||||
{
|
||||
@@ -49,12 +51,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public DataModelPathSegmentType Type { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of dynamic data model this path points to
|
||||
/// <para>Not used if the <see cref="Type" /> is <see cref="DataModelPathSegmentType.Static" /></para>
|
||||
/// </summary>
|
||||
public Type? DynamicDataModelType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the previous segment in the path
|
||||
/// </summary>
|
||||
@@ -114,7 +110,7 @@ namespace Artemis.Core
|
||||
{
|
||||
// Dynamic types have a data model description
|
||||
if (Type == DataModelPathSegmentType.Dynamic)
|
||||
return (GetValue() as DataModel)?.DataModelDescription;
|
||||
return _dynamicDataModelAttribute;
|
||||
if (IsStartSegment && DataModelPath.Target != null)
|
||||
return DataModelPath.Target.DataModelDescription;
|
||||
if (IsStartSegment)
|
||||
@@ -187,12 +183,12 @@ namespace Artemis.Core
|
||||
return CreateExpression(parameter, expression, nullCondition);
|
||||
|
||||
// If a dynamic data model is found the use that
|
||||
bool hasDynamicDataModel = _dynamicDataModel.DynamicDataModels.TryGetValue(Identifier, out DataModel? dynamicDataModel);
|
||||
if (hasDynamicDataModel && dynamicDataModel != null)
|
||||
DetermineDynamicType(dynamicDataModel);
|
||||
bool hasDynamicChild = _dynamicDataModel.DynamicChildren.TryGetValue(Identifier, out DynamicChild? dynamicChild);
|
||||
if (hasDynamicChild && dynamicChild?.Value != null)
|
||||
DetermineDynamicType(dynamicChild.Value, dynamicChild.Attribute);
|
||||
|
||||
_dynamicDataModel.DynamicDataModelAdded += DynamicDataModelOnDynamicDataModelAdded;
|
||||
_dynamicDataModel.DynamicDataModelRemoved += DynamicDataModelOnDynamicDataModelRemoved;
|
||||
_dynamicDataModel.DynamicChildAdded += DynamicChildOnDynamicChildAdded;
|
||||
_dynamicDataModel.DynamicChildRemoved += DynamicChildOnDynamicChildRemoved;
|
||||
}
|
||||
|
||||
return CreateExpression(parameter, expression, nullCondition);
|
||||
@@ -219,7 +215,7 @@ namespace Artemis.Core
|
||||
accessorExpression = Expression.Call(
|
||||
expression,
|
||||
nameof(DataModel.DynamicChild),
|
||||
DynamicDataModelType != null ? new[] {DynamicDataModelType} : null,
|
||||
_dynamicDataModelType != null ? new[] { _dynamicDataModelType } : null,
|
||||
Expression.Constant(Identifier)
|
||||
);
|
||||
|
||||
@@ -236,10 +232,11 @@ namespace Artemis.Core
|
||||
return accessorExpression;
|
||||
}
|
||||
|
||||
private void DetermineDynamicType(DataModel dynamicDataModel)
|
||||
private void DetermineDynamicType(object dynamicDataModel, DataModelPropertyAttribute attribute)
|
||||
{
|
||||
Type = DataModelPathSegmentType.Dynamic;
|
||||
DynamicDataModelType = dynamicDataModel.GetType();
|
||||
_dynamicDataModelType = dynamicDataModel.GetType();
|
||||
_dynamicDataModelAttribute = attribute;
|
||||
}
|
||||
|
||||
private void DetermineStaticType(Type previousType)
|
||||
@@ -263,8 +260,8 @@ namespace Artemis.Core
|
||||
{
|
||||
if (_dynamicDataModel != null)
|
||||
{
|
||||
_dynamicDataModel.DynamicDataModelAdded -= DynamicDataModelOnDynamicDataModelAdded;
|
||||
_dynamicDataModel.DynamicDataModelRemoved -= DynamicDataModelOnDynamicDataModelRemoved;
|
||||
_dynamicDataModel.DynamicChildAdded -= DynamicChildOnDynamicChildAdded;
|
||||
_dynamicDataModel.DynamicChildRemoved -= DynamicChildOnDynamicChildRemoved;
|
||||
}
|
||||
|
||||
Type = DataModelPathSegmentType.Invalid;
|
||||
@@ -285,15 +282,15 @@ namespace Artemis.Core
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void DynamicDataModelOnDynamicDataModelAdded(object? sender, DynamicDataModelEventArgs e)
|
||||
private void DynamicChildOnDynamicChildAdded(object? sender, DynamicDataModelChildEventArgs e)
|
||||
{
|
||||
if (e.Key == Identifier)
|
||||
DataModelPath.Initialize();
|
||||
}
|
||||
|
||||
private void DynamicDataModelOnDynamicDataModelRemoved(object? sender, DynamicDataModelEventArgs e)
|
||||
private void DynamicChildOnDynamicChildRemoved(object? sender, DynamicDataModelChildEventArgs e)
|
||||
{
|
||||
if (e.DynamicDataModel == _dynamicDataModel)
|
||||
if (e.DynamicChild == _dynamicDataModel)
|
||||
DataModelPath.Initialize();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user