Skip to content

Commit

Permalink
makes Currency implement ICurrency from TeixeiraSoftware.Finance.Money
Browse files Browse the repository at this point in the history
  • Loading branch information
André Marcondes Teixeira committed Feb 23, 2018
1 parent 351564d commit bb765b7
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 291 deletions.
48 changes: 25 additions & 23 deletions currency.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Currency", "src\Currency.csproj", "{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Currency", "src\Currency.csproj", "{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CurrencyTest", "test\CurrencyTest.csproj", "{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurrencyTest", "test\CurrencyTest.csproj", "{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,33 +15,36 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x64.ActiveCfg = Debug|x64
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x64.Build.0 = Debug|x64
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x86.ActiveCfg = Debug|x86
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x86.Build.0 = Debug|x86
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x64.ActiveCfg = Debug|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x64.Build.0 = Debug|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x86.ActiveCfg = Debug|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Debug|x86.Build.0 = Debug|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|Any CPU.Build.0 = Release|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x64.ActiveCfg = Release|x64
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x64.Build.0 = Release|x64
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x86.ActiveCfg = Release|x86
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x86.Build.0 = Release|x86
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x64.ActiveCfg = Release|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x64.Build.0 = Release|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x86.ActiveCfg = Release|Any CPU
{5AC2463A-7695-4A6D-89E7-DE01DD7E6C7F}.Release|x86.Build.0 = Release|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x64.ActiveCfg = Debug|x64
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x64.Build.0 = Debug|x64
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x86.ActiveCfg = Debug|x86
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x86.Build.0 = Debug|x86
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x64.ActiveCfg = Debug|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x64.Build.0 = Debug|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x86.ActiveCfg = Debug|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Debug|x86.Build.0 = Debug|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|Any CPU.Build.0 = Release|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x64.ActiveCfg = Release|x64
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x64.Build.0 = Release|x64
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x86.ActiveCfg = Release|x86
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x86.Build.0 = Release|x86
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x64.ActiveCfg = Release|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x64.Build.0 = Release|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x86.ActiveCfg = Release|Any CPU
{4FBE5EA3-C320-4A13-9302-EDFD6745A2DB}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B9CD3B4C-3396-4E9F-AC7F-994AC4DC1A8C}
EndGlobalSection
EndGlobal
30 changes: 9 additions & 21 deletions src/TeixeiraSoftware/Finance/Currency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,8 @@ namespace TeixeiraSoftware.Finance
/// </see>
/// </para>
/// </remarks>
public partial struct Currency : IEquatable<Currency>
public partial class Currency : ICurrency
{
/// <summary>The 3 letters ISO code of the currency</summary>
public string LetterCode { get; }

/// <summary>The ISO minor units of the currency</summary>
public byte MinorUnits { get; }

/// <summary>The ISO name of the currency</summary>
public string Name { get; }

/// <summary>The numeric ISO code of the currency</summary>
public string NumericCode { get; }

/// <summary>
/// Initializes a new instance of the <see cref="Currency" /> class.
/// </summary>
Expand All @@ -51,16 +39,16 @@ public partial struct Currency : IEquatable<Currency>
/// var currency = Currency.GetByNumericCode("999");
/// </code>
/// </example>
/// <param name="letterCode">The 3 letters ISO code of the Currency.</param>
/// <param name="alphabeticCode">The 3 letters ISO code of the Currency.</param>
/// <param name="numericCode">The 3 digits numeric ISO code of the Currency.</param>
/// <param name="minorUnits">The ISO minor units of the Currency.</param>
/// <param name="name">The ISO name of the Currency.</param>
public Currency(string letterCode, string numericCode, byte minorUnits, string name)
{
this.LetterCode = letterCode;
this.NumericCode = numericCode;
this.MinorUnits = minorUnits;
this.Name = name;
}
public Currency(
string alphabeticCode,
string numericCode,
byte minorUnits,
string name
) : base(alphabeticCode, numericCode, minorUnits, name)
{ }
}
}
4 changes: 2 additions & 2 deletions src/TeixeiraSoftware/Finance/CurrencyAllCurrenciesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

namespace TeixeiraSoftware.Finance
{
public partial struct Currency : IEquatable<Currency>
public partial class Currency : ICurrency
{
/// <summary>A list of all the currencies.</summary>
public static readonly IList<Currency> AllCurrencies = new List<Currency>
public static readonly IList<ICurrency> AllCurrencies = new List<ICurrency>
{
Currency.AED,
Currency.AFN,
Expand Down
2 changes: 1 addition & 1 deletion src/TeixeiraSoftware/Finance/CurrencyFactoryProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TeixeiraSoftware.Finance
{
public partial struct Currency : IEquatable<Currency>
public partial class Currency : ICurrency
{
/// <summary>UAE Dirham</summary>
public static Currency AED
Expand Down
35 changes: 35 additions & 0 deletions src/TeixeiraSoftware/Finance/CurrencyIComparableImplementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace TeixeiraSoftware.Finance
{
public partial class Currency : ICurrency
{
/// <summary>
/// Compares two currencies for sorting purposes
/// </summary>
/// <param name="other"></param>
/// <returns>
/// -1 if this current currency comes before the other currency.
/// 0 if this current currency is equal to the other currency.
/// 1 if this current currency comes after the other currency.
/// </returns>
public override int CompareTo(object other)
{
throw new NotImplementedException();
}

/// <summary>
/// Compares two currencies for sorting purposes
/// </summary>
/// <param name="other"></param>
/// <returns>
/// -1 if this current currency comes before the other currency.
/// 0 if this current currency is equal to the other currency.
/// 1 if this current currency comes after the other currency.
/// </returns>
public override int CompareTo(ICurrency other)
{
throw new NotImplementedException();
}
}
}
33 changes: 33 additions & 0 deletions src/TeixeiraSoftware/Finance/CurrencyIEquatableImplementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace TeixeiraSoftware.Finance
{
public partial class Currency : ICurrency
{
/// <summary>Compares the equality of two currencies.</summary>
/// <remarks>
/// The instances of <see cref="Currency" /> class are compared through their
/// whole set of properties.
/// </remarks>
/// <param name="currency">An instance of <see cref="Currency" /></param>
public override bool Equals(object currency)
{
return AreEquivalent(this, (ICurrency)currency);
}

/// <summary>Compares the equality of two currencies.</summary>
/// <remarks>
/// The instances of <see cref="ICurrency" /> class are compared through their
/// whole set of properties.
/// </remarks>
/// <param name="currency">An instance of <see cref="ICurrency" /></param>
public override bool Equals(ICurrency currency)
{
return AreEquivalent(this, currency);
}

/// <remarks>The hash code is taken from the base class Object.</remarks>
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
37 changes: 28 additions & 9 deletions src/TeixeiraSoftware/Finance/CurrencyMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,59 @@

namespace TeixeiraSoftware.Finance
{
public partial struct Currency : IEquatable<Currency>
public partial class Currency : ICurrency
{
/// <summary>Gets a currency by its letter code.</summary>
/// <param name="letterCode">The letter code of the desired currency.</param>
/// <summary>Gets a currency by its alphabetic code.</summary>
/// <param name="alphabeticCode">The letter code of the desired currency.</param>
/// <exception cref="System.ArgumentException">
/// Thrown when no currency is found with the specified letter code.
/// </exception>
public static Currency GetByLetterCode(string letterCode)
public static ICurrency ByAlphabeticCode(string alphabeticCode)
{
var filteredCurrencies = Currency.AllCurrencies.Where(currency => currency.LetterCode == letterCode);
var filteredCurrencies = Currency.AllCurrencies.Where(currency => currency.AlphabeticCode == alphabeticCode);

if (filteredCurrencies.Count() > 0)
{
return filteredCurrencies.First();
var currency = filteredCurrencies.First();

return new Currency(currency.AlphabeticCode, currency.NumericCode, currency.MinorUnits, currency.Name);
}

throw new ArgumentException($"There is no registered currency with the letter code {letterCode}.");
throw new ArgumentException($"There is no registered currency with the alphabetic code {alphabeticCode}.");
}

/// <summary>Gets a currency by its numeric code.</summary>
/// <param name="numericCode">The numeric code of the desired currency.</param>
/// <exception cref="System.ArgumentException">
/// Thrown when no currency is found with the specified numeric code.
/// </exception>
public static Currency GetByNumericCode(string numericCode)
public static ICurrency ByNumericCode(string numericCode)
{
var filteredCurrencies = Currency.AllCurrencies.Where(currency => currency.NumericCode == numericCode);

if (filteredCurrencies.Count() > 0)
{
return filteredCurrencies.First();
var currency = filteredCurrencies.First();

return new Currency(currency.AlphabeticCode, currency.NumericCode, currency.MinorUnits, currency.Name);
}

throw new ArgumentException($"There is no registered currency with the numeric code {numericCode}.");
}

/// <summary>
/// Compares two ICurrency instances based on their whole set of properties
/// </summary>
/// <param name="left">An ICurrency instance</param>
/// <param name="right">An ICurrency instance</param>
/// <returns>True of false</returns>
private static bool AreEquivalent(ICurrency left, ICurrency right)
{
return
left.NumericCode == right.NumericCode
&& left.AlphabeticCode == right.AlphabeticCode
&& left.MinorUnits == right.MinorUnits
&& left.Name == right.Name;
}
}
}
39 changes: 1 addition & 38 deletions src/TeixeiraSoftware/Finance/CurrencyOperators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TeixeiraSoftware.Finance
{
public partial struct Currency : IEquatable<Currency>
public partial class Currency : ICurrency
{
/// <summary>Compares the equality of two currencies.</summary>
/// <remarks>
Expand All @@ -23,42 +23,5 @@ public partial struct Currency : IEquatable<Currency>
{
return !AreEquivalent(a, b);
}

/// <summary>Compares the equality of two currencies.</summary>
/// <remarks>
/// The instances of <see cref="Currency" /> class are compared through their
/// whole set of properties.
/// </remarks>
/// <param name="currency">An instance of <see cref="Currency" /></param>
public override bool Equals(object currency)
{
return AreEquivalent(this, (Currency) currency);
}

/// <summary>Compares the equality of two currencies.</summary>
/// <remarks>
/// The instances of <see cref="Currency" /> class are compared through their
/// whole set of properties.
/// </remarks>
/// <param name="currency">An instance of <see cref="Currency" /></param>
public bool Equals(Currency currency)
{
return AreEquivalent(this, currency);
}

/// <remarks>The hash code is taken from the base class Object.</remarks>
public override int GetHashCode()
{
return base.GetHashCode();
}

private static bool AreEquivalent(Currency a, Currency b)
{
return
a.NumericCode == b.NumericCode
&& a.LetterCode == b.LetterCode
&& a.MinorUnits == b.MinorUnits
&& a.Name == b.Name;
}
}
}
21 changes: 12 additions & 9 deletions src/currency.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>TeixeiraSoftware.Finance.Currency</AssemblyName>
<Title>TeixeiraSoftware.Finance.Currency</Title>
<PackageVersion>1.0.0</PackageVersion>
<PackageVersion>4.0.0</PackageVersion>
<AssemblyCompany>Teixeira Software</AssemblyCompany>
<AssemblyDescription>A simple cross platform currency struct that follows the ISO 4217 standard.</AssemblyDescription>
<AssemblyDescription>A simple cross platform currency class that follows the ISO 4217 standard.</AssemblyDescription>
<RootNamespace>TeixeiraSoftware</RootNamespace>
<ApplicationIcon />
<Win32Resource />
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>andremteixeira</Authors>
<Company>Teixeira Software</Company>
<Description>A simple cross platform currency struct that follows the ISO 4217 standard.</Description>
<Description>A simple cross platform currency class that follows the ISO 4217 standard.</Description>
<Copyright>Teixeira Software</Copyright>
<RepositoryUrl>https://github.com/TeixeiraSoftware/Currency</RepositoryUrl>
<RepositoryUrl>https://github.com/TeixeiraSoftware/TeixeiraSoftware.Finance.Currency</RepositoryUrl>
<PackageTags>currency;money;finance;netstandard</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.0</Version>
<PackageProjectUrl>https://github.com/TeixeiraSoftware/Currency</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/TeixeiraSoftware/Currency/master/LICENSE</PackageLicenseUrl>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<FileVersion>4.0.0.0</FileVersion>
<Version>4.0.0</Version>
<PackageProjectUrl>https://teixeirasoftware.github.io/TeixeiraSoftware.Finance.Currency/</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/TeixeiraSoftware/TeixeiraSoftware.Finance.Currency/master/LICENSE</PackageLicenseUrl>
<PackageReleaseNotes>First release.</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -31,4 +31,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.0\TeixeiraSoftware.Finance.Currency.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TeixeiraSoftware.Finance.Money" Version="4.0.1" />
</ItemGroup>
</Project>
Loading

0 comments on commit bb765b7

Please sign in to comment.