Last active
March 5, 2019 22:26
-
-
Save formix/2f5517b47c89d262f5b5b66005d9cd7a to your computer and use it in GitHub Desktop.
Revisions
-
formix revised this gist
Mar 5, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; namespace Template.Project.ViewModels { public class ViewModelBase : INotifyPropertyChanged { -
formix created this gist
Nov 26, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ using System; using System.Collections.Generic; using System.ComponentModel; namespace Tekmar.Gateway486.Mobile.Core.ViewModels { public class ViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private readonly Dictionary<string, object> _properties; public ViewModelBase() { // Makes sure that the internal hash table won't get resized // while being filled. var projectedSize = GetType().GetProperties().Length / 0.7; var size = (int)Math.Ceiling(projectedSize); _properties = new Dictionary<string, object>(size); } protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } protected virtual T Get<T>(string propertyName) { if (!_properties.ContainsKey(propertyName)) { return default(T); } return (T)_properties[propertyName]; } protected virtual void Set(string propertyName, object value) { _properties[propertyName] = value; OnPropertyChanged(propertyName); } } }