forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropertyChangedEventArgsEx.cs
More file actions
60 lines (51 loc) · 2.05 KB
/
PropertyChangedEventArgsEx.cs
File metadata and controls
60 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using UnityEngine;
namespace HoloToolkit.Unity.SpatialMapping
{
public static class PropertyChangedEventArgsEx
{
public static PropertyChangedEventArgsEx<TProperty> Create<TProperty>(string propertyName, TProperty oldValue, TProperty newValue)
{
return new PropertyChangedEventArgsEx<TProperty>(propertyName, oldValue, newValue);
}
public static PropertyChangedEventArgsEx<TProperty> Create<TProperty>(Expression<Func<TProperty>> memberGetter, TProperty oldValue, TProperty newValue)
{
return new PropertyChangedEventArgsEx<TProperty>(memberGetter, oldValue, newValue);
}
}
[Serializable]
public class PropertyChangedEventArgsEx<TProperty> : PropertyChangedEventArgs
{
public TProperty OldValue { get; private set; }
public TProperty NewValue { get; private set; }
public PropertyChangedEventArgsEx(string inPropertyName, TProperty inOldValue, TProperty inNewValue) :
base(inPropertyName)
{
OldValue = inOldValue;
NewValue = inNewValue;
}
public PropertyChangedEventArgsEx(Expression<Func<TProperty>> memberGetter, TProperty inOldValue, TProperty inNewValue) :
this(GetMemberName(memberGetter), inOldValue, inNewValue)
{
// Nothing.
}
private static string GetMemberName(Expression<Func<TProperty>> memberGetter)
{
Debug.Assert(memberGetter.Body is MemberExpression);
string memberName = ((MemberExpression)memberGetter.Body).Member.Name;
return memberName;
}
public override string ToString()
{
return string.Format("{0}: {1} -> {2}",
PropertyName,
OldValue,
NewValue
);
}
}
}