using System.Diagnostics.CodeAnalysis; using Artemis.Core.Modules; using ReactiveUI; namespace Artemis.UI.Shared.DataModelVisualization { /// /// Represents a display view model /// /// The type of the data model public abstract class DataModelDisplayViewModel : DataModelDisplayViewModel { [AllowNull] private T _displayValue = default!; /// /// Gets or sets value that the view model must display /// [AllowNull] public T DisplayValue { get => _displayValue; set { if (Equals(value, _displayValue)) return; RaiseAndSetIfChanged(ref _displayValue, value); OnDisplayValueUpdated(); } } internal override object InternalGuard => new(); /// public override void UpdateValue(object? model) { DisplayValue = model is T value ? value : default; } /// /// Occurs when the display value is updated /// protected virtual void OnDisplayValueUpdated() { } } /// /// For internal use only, implement instead. /// public abstract class DataModelDisplayViewModel : ViewModelBase { private DataModelPropertyAttribute? _propertyDescription; /// /// Gets the property description of this value /// public DataModelPropertyAttribute? PropertyDescription { get => _propertyDescription; internal set => RaiseAndSetIfChanged(ref _propertyDescription, value); } /// /// Prevents this type being implemented directly, implement instead. /// internal abstract object InternalGuard { get; } /// /// Updates the display value /// /// The value to set public abstract void UpdateValue(object? model); } }