refactoring
parent
167a9861a4
commit
c5274146e3
@ -0,0 +1,7 @@
|
||||
namespace Yavsc.Models.Market {
|
||||
public interface IUnit<VType> {
|
||||
string Name { get; }
|
||||
bool CanConvertFrom(IUnit<VType> other);
|
||||
VType ConvertFrom (IUnit<VType> other, VType orgValue) ;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.Models.Market {
|
||||
public class Money : IUnit<decimal>
|
||||
{
|
||||
public Money(string name, decimal euroExchangeRate)
|
||||
{
|
||||
Name = name;
|
||||
EuroExchangeRate = euroExchangeRate;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get; private set ;
|
||||
}
|
||||
|
||||
public decimal EuroExchangeRate
|
||||
{
|
||||
get; private set ;
|
||||
}
|
||||
public bool CanConvertFrom(IUnit<decimal> other)
|
||||
{
|
||||
if (other is Money)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public decimal ConvertFrom(IUnit<decimal> other, decimal orgValue)
|
||||
{
|
||||
if (other is Money) {
|
||||
var om = other as Money;
|
||||
return orgValue * om.EuroExchangeRate / EuroExchangeRate;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue