Data bindings - Simplified getter/setter code

This commit is contained in:
Robert committed 2021-03-02 21:41:56 +01:00
1 parent 267e8e6a1e
commit f4ad41cbd4
38 files changed
+86 -89

No files matched your search

@@ -272,7 +272,7 @@ namespace Artemis.Core
throw new ObjectDisposedException("DataBinding");
// General
DataBindingRegistration<TLayerProperty, TProperty>? registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
DataBindingRegistration<TLayerProperty, TProperty>? registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.Identifier);
if (registration != null)
ApplyRegistration(registration);
@@ -293,7 +293,7 @@ namespace Artemis.Core
// Don't save an invalid state
if (Registration != null)
Entity.TargetExpression = Registration.Getter.ToString();
Entity.Identifier = Registration.DisplayName;
Entity.EasingTime = EasingTime;
Entity.EasingFunction = (int) EasingFunction;
@@ -47,7 +47,7 @@ namespace Artemis.Core
{
if (DataBinding?.Registration == null)
throw new ArtemisCoreException("Data binding converter is not yet initialized");
DataBinding.Registration.Setter(DataBinding.LayerProperty.CurrentValue, value);
DataBinding.Registration.Setter(value);
}
/// <summary>
@@ -57,7 +57,7 @@ namespace Artemis.Core
{
if (DataBinding?.Registration == null)
throw new ArtemisCoreException("Data binding converter is not yet initialized");
return DataBinding.Registration.Getter(DataBinding.LayerProperty.CurrentValue);
return DataBinding.Registration.Getter();
}
/// <summary>
@@ -8,9 +8,7 @@ namespace Artemis.Core
public class DataBindingRegistration<TLayerProperty, TProperty> : IDataBindingRegistration
{
internal DataBindingRegistration(LayerProperty<TLayerProperty> layerProperty, DataBindingConverter<TLayerProperty, TProperty> converter,
Func<TLayerProperty, TProperty> getter,
Action<TLayerProperty, TProperty> setter,
string displayName)
Func<TProperty> getter, Action<TProperty> setter, string displayName)
{
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
Converter = converter ?? throw new ArgumentNullException(nameof(converter));
@@ -32,17 +30,15 @@ namespace Artemis.Core
/// <summary>
/// Gets the function to call to get the value of the property
/// </summary>
public Func<TLayerProperty, TProperty> Getter { get; }
public Func<TProperty> Getter { get; }
/// <summary>
/// Gets the action to call to set the value of the property
/// </summary>
public Action<TLayerProperty, TProperty> Setter { get; }
public Action<TProperty> Setter { get; }
/// <summary>
/// Gets or sets the display name of the data binding registration
/// </summary>
public string DisplayName { get; set; }
/// <inheritdoc />
public string DisplayName { get; }
/// <summary>
/// Gets the data binding created using this registration
@@ -61,7 +57,7 @@ namespace Artemis.Core
if (DataBinding != null)
return DataBinding;
DataBindingEntity? dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == Getter.ToString());
DataBindingEntity? dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.Identifier == DisplayName);
if (dataBinding == null)
return null;
@@ -5,6 +5,11 @@
/// </summary>
public interface IDataBindingRegistration
{
/// <summary>
/// Gets or sets the display name of the data binding registration
/// </summary>
string DisplayName { get; }
/// <summary>
/// Returns the data binding applied using this registration
/// </summary>