diff options
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Utilities')
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs | 35 | ||||
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs | 86 |
2 files changed, 121 insertions, 0 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs b/win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs new file mode 100644 index 000000000..53db9e23f --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs @@ -0,0 +1,35 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace HandBrake.ApplicationServices.Utilities
+{
+ using System.Linq.Expressions;
+ using System.Reflection;
+
+ public static class ExtensionMethods
+ {
+ /// <summary>
+ /// Converts an expression into a <see cref="MemberInfo"/>.
+ /// </summary>
+ /// <param name="expression">The expression to convert.</param>
+ /// <returns>The member info.</returns>
+ public static MemberInfo GetMemberInfo(this Expression expression)
+ {
+ var lambda = (LambdaExpression)expression;
+
+ MemberExpression memberExpression;
+ if (lambda.Body is UnaryExpression)
+ {
+ var unaryExpression = (UnaryExpression)lambda.Body;
+ memberExpression = (MemberExpression)unaryExpression.Operand;
+ }
+ else
+ memberExpression = (MemberExpression)lambda.Body;
+
+ return memberExpression.Member;
+ }
+
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs new file mode 100644 index 000000000..9809def57 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs @@ -0,0 +1,86 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="PropertyChangedBase.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling.
+// This class is a modified version of the caliburn micro
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Utilities
+{
+ using System;
+ using System.ComponentModel;
+ using System.Linq.Expressions;
+ using System.Runtime.Serialization;
+
+ /// <summary>
+ /// Property Changed Base implimentation.
+ /// </summary>
+ [DataContract]
+ public class PropertyChangedBase : INotifyPropertyChanged
+ {
+ /// <summary>
+ /// Creates an instance of <see cref = "PropertyChangedBase" />.
+ /// </summary>
+ public PropertyChangedBase()
+ {
+ IsNotifying = true;
+ }
+
+ /// <summary>
+ /// Occurs when a property value changes.
+ /// </summary>
+ public event PropertyChangedEventHandler PropertyChanged = delegate { };
+
+ /// <summary>
+ /// Enables/Disables property change notification.
+ /// </summary>
+ public bool IsNotifying { get; set; }
+
+ /// <summary>
+ /// Raises a change notification indicating that all bindings should be refreshed.
+ /// </summary>
+ public virtual void Refresh()
+ {
+ NotifyOfPropertyChange(string.Empty);
+ }
+
+ /// <summary>
+ /// Notifies subscribers of the property change.
+ /// </summary>
+ /// <param name = "propertyName">Name of the property.</param>
+ public virtual void NotifyOfPropertyChange(string propertyName = null)
+ {
+ if (IsNotifying)
+ {
+ OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ /// <summary>
+ /// Notifies subscribers of the property change.
+ /// </summary>
+ /// <typeparam name = "TProperty">The type of the property.</typeparam>
+ /// <param name = "property">The property expression.</param>
+ public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
+ {
+ NotifyOfPropertyChange(property.GetMemberInfo().Name);
+ }
+
+ /// <summary>
+ /// Raises the <see cref="PropertyChanged" /> event directly.
+ /// </summary>
+ /// <param name="e">The <see cref="PropertyChangedEventArgs"/> instance containing the event data.</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected void OnPropertyChanged(PropertyChangedEventArgs e)
+ {
+ var handler = PropertyChanged;
+ if (handler != null)
+ {
+ handler(this, e);
+ }
+ }
+ }
+}
|