Skip to content

Instantly share code, notes, and snippets.

@mastoj
Created June 11, 2015 11:39
Show Gist options
  • Save mastoj/3101b1e78b42ef290056 to your computer and use it in GitHub Desktop.
Save mastoj/3101b1e78b42ef290056 to your computer and use it in GitHub Desktop.
Simple implementation of money for C#
namespace Money
{
public class Money<TCurrency> where TCurrency : ICurrency
{
private readonly decimal _value;
public Money(decimal value)
{
_value = value;
}
public Money<TCurrency> MultiplyBy(decimal multiplier)
{
return new Money<TCurrency>(this._value*multiplier);
}
protected bool Equals(Money<TCurrency> other)
{
return _value == other._value;
}
public override bool Equals(object obj)
{
if (obj is Money<TCurrency>)
{
var that = (Money<TCurrency>) obj;
return this._value == that._value;
}
return false;
}
}
public interface ICurrency
{
}
public class Dollar : ICurrency{}
public class NOK : ICurrency{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment