Skip to content

Commit

Permalink
refactor: remove PropertyInfo from strongly-type change handler callback
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavisau committed Apr 25, 2019
1 parent 9d64121 commit 1ca6f51
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/DumpEditable/EditableDumpContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public partial class EditableDumpContainer<T> : DumpContainer
{
private readonly T _obj;
private readonly bool _failSilently;
private readonly Dictionary<PropertyInfo, Action<T, PropertyInfo, object>> _changeHandlers
= new Dictionary<PropertyInfo, Action<T, PropertyInfo, object>>();
private readonly Dictionary<PropertyInfo, Action<T, object>> _changeHandlers
= new Dictionary<PropertyInfo, Action<T, object>>();

private readonly List<EditorRule> _editorRules = new List<EditorRule>();

Expand All @@ -27,13 +27,13 @@ public static void AddGlobalEditorRule(EditorRule rule)
=> GlobalEditorRules.Insert(0, rule);

public void AddChangeHandler<U>(Expression<Func<T, U>> selector,
Action<T, PropertyInfo, U> onChangedAction)
Action<T, U> onChangedAction)
{
var pi = (selector.Body as MemberExpression)?.Member as PropertyInfo;
if (pi is null)
throw new Exception($"Invalid expression passed to {nameof(AddChangeHandler)}");

_changeHandlers[pi] = (obj, p, val) => onChangedAction(obj, p, (U) val);
_changeHandlers[pi] = (obj, val) => onChangedAction(obj, (U) val);
}

public void AddEditorRule(EditorRule rule)
Expand Down Expand Up @@ -129,7 +129,7 @@ private object GetPropertyEditor(object o, PropertyInfo p)
var newVal = p.GetValue(o);
if (_changeHandlers.TryGetValue(p, out var handler))
handler.Invoke((T)o,p,newVal);
handler.Invoke((T)o,newVal);
OnPropertyValueChanged?.Invoke((T)o, p, newVal);
Expand Down

0 comments on commit 1ca6f51

Please sign in to comment.