AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
PropertyChangedEventArgsEx.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using System.ComponentModel;
6 using System.Linq.Expressions;
7 using UnityEngine;
8 
9 namespace HoloToolkit.Unity.SpatialMapping
10 {
11  public static class PropertyChangedEventArgsEx
12  {
13  public static PropertyChangedEventArgsEx<TProperty> Create<TProperty>(string propertyName, TProperty oldValue, TProperty newValue)
14  {
15  return new PropertyChangedEventArgsEx<TProperty>(propertyName, oldValue, newValue);
16  }
17 
18  public static PropertyChangedEventArgsEx<TProperty> Create<TProperty>(Expression<Func<TProperty>> memberGetter, TProperty oldValue, TProperty newValue)
19  {
20  return new PropertyChangedEventArgsEx<TProperty>(memberGetter, oldValue, newValue);
21  }
22  }
23 
24  [Serializable]
25  public class PropertyChangedEventArgsEx<TProperty> : PropertyChangedEventArgs
26  {
27  public TProperty OldValue { get; private set; }
28  public TProperty NewValue { get; private set; }
29 
30  public PropertyChangedEventArgsEx(string inPropertyName, TProperty inOldValue, TProperty inNewValue) :
31  base(inPropertyName)
32  {
33  OldValue = inOldValue;
34  NewValue = inNewValue;
35  }
36 
37  public PropertyChangedEventArgsEx(Expression<Func<TProperty>> memberGetter, TProperty inOldValue, TProperty inNewValue) :
38  this(GetMemberName(memberGetter), inOldValue, inNewValue)
39  {
40  // Nothing.
41  }
42 
43  private static string GetMemberName(Expression<Func<TProperty>> memberGetter)
44  {
45  Debug.Assert(memberGetter.Body is MemberExpression);
46 
47  string memberName = ((MemberExpression)memberGetter.Body).Member.Name;
48  return memberName;
49  }
50 
51  public override string ToString()
52  {
53  return string.Format("{0}: {1} -> {2}",
54  PropertyName,
55  OldValue,
56  NewValue
57  );
58  }
59  }
60 }
PropertyChangedEventArgsEx(Expression< Func< TProperty >> memberGetter, TProperty inOldValue, TProperty inNewValue)
PropertyChangedEventArgsEx(string inPropertyName, TProperty inOldValue, TProperty inNewValue)