Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created June 11, 2012 00:56
Show Gist options
  • Save masaru-b-cl/2907933 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/2907933 to your computer and use it in GitHub Desktop.
シンプルな計算機のModel
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