Created
June 11, 2015 11:39
-
-
Save mastoj/3101b1e78b42ef290056 to your computer and use it in GitHub Desktop.
Simple implementation of money for C#
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
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