Files
@ f1d4569c0495
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/ViewModels/ValidatableViewModelBase.cs - annotation
f1d4569c0495
1.7 KiB
text/x-csharp
3 way reactions should now allow you to change the position of the buffer
reagent from first to last.
reagent from first to last.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 | using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
namespace DesertPaintCodex.ViewModels
{
public class ValidatableViewModelBase : ViewModelBase, INotifyDataErrorInfo
{
private static readonly string [] NoErrors = new string[0];
private Dictionary <string, List<string>> _errorsByPropertyName = new () ;
public IEnumerable GetErrors(string? propertyName)
{
if (propertyName != null && _errorsByPropertyName. TryGetValue(propertyName, out var errorList))
{
return errorList;
}
return NoErrors;
}
protected virtual void SetError(string propertyName, string error)
{
if (_errorsByPropertyName.TryGetValue(propertyName, out var errorList))
{
if (!errorList.Contains(error))
{
errorList.Add(error);
}
}
else
{
_errorsByPropertyName.Add(propertyName, new List<string> {error});
}
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
}
protected virtual void RemoveErrors(string propertyName)
{
if (_errorsByPropertyName.ContainsKey(propertyName))
{
_errorsByPropertyName.Remove(propertyName);
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
}
}
public bool HasErrors => _errorsByPropertyName.Count > 0 ;
public event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
}
}
|