mirror of
https://github.com/farcasclaudiu/myfriendsaround.git
synced 2026-06-29 11:02:07 +03:00
00f97e41d6
http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/01/14/windows-push-notification-server-side-helper-library.aspx http://create.msdn.com/en-us/education/catalog/article/pnhelp-wp7
92 lines
3.0 KiB
C#
92 lines
3.0 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Windows.Threading;
|
|
using System.Windows;
|
|
|
|
namespace WindowsPhone.Recipes.Push.Server.ViewModels
|
|
{
|
|
/// <summary>
|
|
/// Base class for all ViewModel classes in the application.
|
|
/// It provides support for property change notifications
|
|
/// and has a DisplayName property. This class is abstract.
|
|
/// </summary>
|
|
public abstract class ViewModelBase : INotifyPropertyChanged
|
|
{
|
|
#region Properties
|
|
|
|
public Dispatcher Dispatcher
|
|
{
|
|
get { return Application.Current.Dispatcher; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected ViewModelBase()
|
|
{
|
|
}
|
|
|
|
#endregion // Constructor
|
|
|
|
#region Debugging
|
|
|
|
/// <summary>
|
|
/// Warns the developer if this object does not have
|
|
/// a public property with the specified name. This
|
|
/// method does not exist in a Release build.
|
|
/// </summary>
|
|
[Conditional("DEBUG")]
|
|
[DebuggerStepThrough]
|
|
public void VerifyPropertyName(string propertyName)
|
|
{
|
|
// Verify that the property name matches a real,
|
|
// public, instance property on this object.
|
|
if (TypeDescriptor.GetProperties(this)[propertyName] == null)
|
|
{
|
|
string msg = "Invalid property name: " + propertyName;
|
|
|
|
if (this.ThrowOnInvalidPropertyName)
|
|
throw new Exception(msg);
|
|
else
|
|
Debug.Fail(msg);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns whether an exception is thrown, or if a Debug.Fail() is used
|
|
/// when an invalid property name is passed to the VerifyPropertyName method.
|
|
/// The default value is false, but subclasses used by unit tests might
|
|
/// override this property's getter to return true.
|
|
/// </summary>
|
|
protected virtual bool ThrowOnInvalidPropertyName { get; private set; }
|
|
|
|
#endregion // Debugging Aides
|
|
|
|
#region INotifyPropertyChanged Members
|
|
|
|
/// <summary>
|
|
/// Raised when a property on this object has a new value.
|
|
/// </summary>
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
/// <summary>
|
|
/// Raises this object's PropertyChanged event.
|
|
/// </summary>
|
|
/// <param name="propertyName">The property that has a new value.</param>
|
|
protected void NotifyPropertyChanged(string propertyName)
|
|
{
|
|
this.VerifyPropertyName(propertyName);
|
|
|
|
PropertyChangedEventHandler handler = this.PropertyChanged;
|
|
if (handler != null)
|
|
{
|
|
var e = new PropertyChangedEventArgs(propertyName);
|
|
handler(this, e);
|
|
}
|
|
}
|
|
|
|
#endregion // INotifyPropertyChanged Members
|
|
}
|
|
} |