Created
June 11, 2012 00:56
-
-
Save masaru-b-cl/2907933 to your computer and use it in GitHub Desktop.
シンプルな計算機のModel
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 characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.ComponentModel; | |
namespace MVVMCalculator | |
{ | |
public class Calculator : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
private void OnPropertyChanged(PropertyChangedEventArgs e) | |
{ | |
var propertyChanged = PropertyChanged; | |
if (propertyChanged != null) | |
{ | |
propertyChanged(this, e); | |
} | |
} | |
private decimal result; | |
public decimal Result | |
{ | |
get | |
{ | |
return this.result; | |
} | |
protected set | |
{ | |
if (this.result != value) | |
{ | |
this.result = value; | |
OnPropertyChanged(new PropertyChangedEventArgs("Result")); | |
} | |
} | |
} | |
public void Add(decimal value) | |
{ | |
this.Result += value; | |
} | |
public void Subtract(decimal value) | |
{ | |
this.Result -= value; | |
} | |
public void Multiply(decimal value) | |
{ | |
this.Result *= value; | |
} | |
public void Divide(decimal value) | |
{ | |
this.Result /= value; | |
} | |
public void Clear() | |
{ | |
this.Result = 0m; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment