mirror of
https://github.com/holgerb83/ModernWpfPlayground.git
synced 2025-06-30 09:40:52 +02:00
switched to yaml as filee format
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using FastMember;
|
||||
using Prism.Mvvm;
|
||||
@ -21,7 +22,7 @@ namespace ModernWpfPlayground.MvvmStuff
|
||||
protected bool SetProperty<T>(T value, Action<T>? onChanged = null,
|
||||
[CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
if(propertyName == null) throw new ArgumentNullException(nameof(propertyName));
|
||||
if (propertyName == null) throw new ArgumentNullException(nameof(propertyName));
|
||||
if (_values.TryGetValue(propertyName, out var obj) && Equals(value, obj)) return false;
|
||||
|
||||
_values[propertyName] = value!;
|
||||
@ -33,12 +34,14 @@ namespace ModernWpfPlayground.MvvmStuff
|
||||
protected T GetProperty<T>(T defaultValue = default, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
if (propertyName == null) throw new ArgumentNullException(nameof(propertyName));
|
||||
return Values.TryGetValue(propertyName, out var obj) ? (T) obj : defaultValue;
|
||||
return Values.TryGetValue(propertyName, out var obj) ? (T)obj : defaultValue;
|
||||
}
|
||||
|
||||
protected void ResetViewModel()
|
||||
protected void ResetViewModel(Func<string, bool>? predicate = null)
|
||||
{
|
||||
foreach (var key in Values.Keys)
|
||||
IEnumerable<string> keys = _values.Keys;
|
||||
if (predicate != null) keys = keys.Where(predicate);
|
||||
foreach (var key in keys)
|
||||
{
|
||||
_values.Remove(key);
|
||||
RaisePropertyChanged(key);
|
||||
@ -49,10 +52,14 @@ namespace ModernWpfPlayground.MvvmStuff
|
||||
|
||||
protected void LoadViewModel()
|
||||
{
|
||||
var keysFromFile = new SortedSet<string>();
|
||||
foreach (var (key, value) in GetViewModelItems())
|
||||
{
|
||||
keysFromFile.Add(key);
|
||||
ObjectAccessor[key] = value;
|
||||
}
|
||||
|
||||
ResetViewModel(x => !keysFromFile.Contains(x));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user