Skip to content

Commit

Permalink
Merge pull request #48 from remyvd/release-1.0.0
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
Rémy van Duijkeren authored Oct 10, 2016
2 parents f4460da + 9ede3c5 commit 2c4b3d8
Show file tree
Hide file tree
Showing 18 changed files with 598 additions and 314 deletions.
1 change: 1 addition & 0 deletions NodaMoney.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
build\default.ps1 = build\default.ps1
global.json = global.json
src\GlobalAssemblyInfo.cs = src\GlobalAssemblyInfo.cs
README.md = README.md
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NodaMoney", "src\NodaMoney\NodaMoney.xproj", "{58F0FE5E-E139-4ABF-B9A5-969DBBE69F52}"
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
NodaMoney
=========
<img align="right" src="https://raw.githubusercontent.com/remyvd/NodaMoney/master/docs/logo_nodamoney.png">
You can get the latest stable release from the [official Nuget.org feed](https://www.nuget.org/packages/NodaMoney) or from our
You can get the latest stable release or prerelease from the [official Nuget.org feed](https://www.nuget.org/packages/NodaMoney) or from our
[github releases page](https://github.com/remyvd/NodaMoney/releases).

If you'd like to work with the bleeding edge, you can use our [custom Nuget feed](https://ci.appveyor.com/nuget/nodamoney-pmrx3j3p32f2).
Packages on this feed are pre-release and, while they've passed all our tests, are not yet ready for production.
Packages on this feed are alpha and beta and, while they've passed all our tests, are not yet ready for production.

For support, bugs and new ideas use [GitHub issues](https://github.com/remyvd/NodaMoney/issues). Please see our
[guidelines](CONTRIBUTING.md) for contributing to the NodaMoney.

[![Build status](https://ci.appveyor.com/api/projects/status/o656q9bagslgusj9?svg=true)](https://ci.appveyor.com/project/remyvd/nodamoney)
[![Coverage Status](https://coveralls.io/repos/remyvd/NodaMoney/badge.svg?branch=develop)](https://coveralls.io/r/remyvd/NodaMoney)
[![Coverage Status](https://coveralls.io/repos/remyvd/NodaMoney/badge.svg?branch=master)](https://coveralls.io/r/remyvd/NodaMoney)

See [http://www.nodamoney.org/](http://www.nodamoney.org/) for more information about this project or below.

About
----
Expand Down Expand Up @@ -180,22 +181,24 @@ Money.TryParse("€ 765,43", Currency.FromCode("EUR"), out euro);
**Adding custom currencies**

```C#
// Create custom currency and register it (for the life-time of the app domain)
// Build custom currency
var builder = new CurrencyBuilder("BTC", "virtual")
{
EnglishName = "Bitcoin",
Symbol = "฿",
DecimalDigits = 8
};

var bitcoin = builder.Build(); // build BTC, but will not register it
var bitcoin = builder.Register(); // build and register BTC in namespace 'virtual'
// Build, but will not register it
var bitcoin = builder.Build();
Money bitcoins = new Money(1.2, bitcoin);

// When the custom is registered, it can be called as any other currency
// Build and register it for the life-time of the app domain in the namespace 'virtual'
var bitcoin = builder.Register();
Money bitcoins = new Money(1.2, "BTC"); // works if no overlap with other namespaces
Money bitcoins = new Money(1.2, Currency.FromCode("BTC", "virtual"));
Money bitcoins = new Money(1.2. "BTC");

// Replace ISO 4217 currency (for the life-time of the app domain)
// Replace ISO 4217 currency for the life-time of the app domain
Currency oldEuro = CurrencyBuilder.Unregister("EUR", "ISO-4217");

var builder = new CurrencyBuilder("EUR", "ISO-4217");
Expand Down
6 changes: 3 additions & 3 deletions build/default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ function Install-Dotnet {
{
$dotnetPath = "$pwd\.dotnet"
$dotnetCliVersion = if ($env:DOTNET_CLI_VERSION -eq $null) { 'Latest' } else { $env:DOTNET_CLI_VERSION }
$dotnetInstallScriptUrl = 'https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/install.ps1'
$dotnetInstallScriptPath = '.\scripts\obtain\install.ps1'
$dotnetInstallScriptUrl = 'https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1'
$dotnetInstallScriptPath = '.\scripts\obtain\dotnet-install.ps1'

md -Force ".\scripts\obtain\" | Out-Null
curl $dotnetInstallScriptUrl -OutFile $dotnetInstallScriptPath
& .\scripts\obtain\install.ps1 -Channel "preview" -version $dotnetCliVersion -InstallDir $dotnetPath -NoPath
& .\scripts\obtain\dotnet-install.ps1 -Channel "preview" -version $dotnetCliVersion -InstallDir $dotnetPath -NoPath
$env:Path = "$dotnetPath;$env:Path"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//// using GitVersion (https://github.com/ParticularLabs/GitVersion).
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0-rc.5")]
[assembly: AssemblyInformationalVersion("1.0.0-beta.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down
11 changes: 6 additions & 5 deletions src/NodaMoney.Serialization.AspNet/project.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"version": "1.0.0-rc0005",
"version": "1.0.0-beta0000",
"title": "NodaMoney.Serialization.AspNet",
"description": "JavaScriptSerializer support for NodaMoney structures.",
"language": "en-US",
"authors": [ "Rémy van Duijkeren" ],
"copyright": "Copyright 2014-2016",
"authors": [ "Rémy van Duijkeren" ],
"copyright": "Copyright Rémy van Duijkeren",
"packOptions": {
"projectUrl": "http://www.nodamoney.org/",
"tags": [ "Noda", "Money", "Currency", "ExchangeRate", "Serialization" ],
Expand All @@ -16,11 +16,12 @@
"url": "https://github.com/remyvd/NodaMoney"
}
},
"buildOptions": {
"xmlDoc": true
},
"dependencies": {
"NETStandard.Library": "1.6.0",
"NodaMoney": "1.0.0-*"
},

"frameworks": {
"net40": {
"frameworkAssemblies": {
Expand Down
45 changes: 19 additions & 26 deletions src/NodaMoney/Currency.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
#if !PORTABLE
using System.Diagnostics.CodeAnalysis;
using System.Xml.Serialization;
#endif

Expand All @@ -16,17 +16,14 @@ namespace NodaMoney
/// <remarks>See http://en.wikipedia.org/wiki/Currency .</remarks>
[DataContract]
[DebuggerDisplay("{Code}")]

public struct Currency : IEquatable<Currency>
#if !PORTABLE
, IXmlSerializable
#endif
{
internal static readonly CurrencyRegistry Registry = new CurrencyRegistry();

/// <summary>
/// Initializes a new instance of the <see cref="Currency" /> struct.
/// </summary>
/// <summary>Initializes a new instance of the <see cref="Currency" /> struct.</summary>
/// <param name="code">The code.</param>
/// <param name="number">The number.</param>
/// <param name="decimalDigits">The decimal digits.</param>
Expand All @@ -41,13 +38,15 @@ internal Currency(string code, string number, double decimalDigits, string engli
: this()
{
if (string.IsNullOrWhiteSpace(code))
throw new ArgumentNullException(nameof(code));
if (string.IsNullOrWhiteSpace(number))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(code));
if (number == null)
throw new ArgumentNullException(nameof(number));
if (string.IsNullOrWhiteSpace(englishName))
throw new ArgumentNullException(nameof(englishName));
throw new ArgumentException("Value cannot be null or whitespace.", nameof(englishName));
if (string.IsNullOrWhiteSpace(symbol))
throw new ArgumentNullException(nameof(symbol));
throw new ArgumentException("Value cannot be null or whitespace.", nameof(symbol));
if (string.IsNullOrWhiteSpace(@namespace))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(@namespace));
if (decimalDigits < 0 && decimalDigits != CurrencyRegistry.NotApplicable)
throw new ArgumentOutOfRangeException(nameof(code), "DecimalDigits must greater or equal to zero!");

Expand All @@ -65,6 +64,10 @@ internal Currency(string code, string number, double decimalDigits, string engli
/// <value>The Currency that represents the country/region used by the current thread.</value>
public static Currency CurrentCurrency => FromRegion(RegionInfo.CurrentRegion);

/// <summary>Gets the currency sign (¤), a character used to denote an unspecified currency.</summary>
/// <remarks><seealso cref="https://en.wikipedia.org/wiki/Currency_sign_(typography)"/></remarks>
public static string CurrencySign => CultureInfo.InvariantCulture.NumberFormat.CurrencySymbol;

/// <summary>Gets the currency symbol.</summary>
public string Symbol { get; private set; }

Expand Down Expand Up @@ -108,7 +111,9 @@ internal Currency(string code, string number, double decimalDigits, string engli
public DateTime? ValidTo { get; internal set; }

/// <summary>Gets the major currency unit.</summary>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Member of Currency type!")]
#if !PORTABLE
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Member of Currency type! Implementation can change in the future.")]
#endif
public decimal MajorUnit => 1;

/// <summary>Gets the minor currency unit.</summary>
Expand Down Expand Up @@ -139,8 +144,6 @@ public static Currency FromCode(string code)
throw new ArgumentException($"{code} is an unknown currency code!");

return currency;

// return FromCode(code, "ISO-4217");
}

/// <summary>Create an instance of the <see cref="Currency"/> of the given code and namespace.</summary>
Expand Down Expand Up @@ -236,7 +239,9 @@ public static IEnumerable<Currency> GetAllCurrencies()
/// <param name="left">The first <see cref="Currency"/> object.</param>
/// <param name="right">The second <see cref="Currency"/> object.</param>
/// <returns>true if left and right are equal to this instance; otherwise, false.</returns>
#if !PORTABLE
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Calling override method")]
#endif
public static bool Equals(Currency left, Currency right)
{
return left.Equals(right);
Expand All @@ -253,7 +258,9 @@ public override bool Equals(object obj)
/// <summary>Returns a value indicating whether this instance and a specified <see cref="Currency"/> object represent the same value.</summary>
/// <param name="other">A <see cref="Currency"/> object.</param>
/// <returns>true if value is equal to this instance; otherwise, false.</returns>
#if !PORTABLE
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Calling override method")]
#endif
public bool Equals(Currency other)
{
return Equals(this.Code, other.Code);
Expand All @@ -266,20 +273,6 @@ public override int GetHashCode()
return Code.GetHashCode();
}

///// <summary>Gets the name of the currency, formatted in the native language of the country\region where the currency is used.</summary>
///// <param name="culture">The culture.</param>
///// <returns>The native name of the currency.</returns>
////public string GetNativeName(CultureInfo culture)
////{
//// //Require.That(culture, "culture").IsNotNull();
//// RegionInfo region = new RegionInfo(culture.Name);
//// if (!region.ISOCurrencySymbol.Equals(Code))
//// {
//// throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.NativeNameDoesNotExistForCulture, Code, culture));
//// }
//// return region.CurrencyNativeName;
////}

/// <summary>This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should
/// return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply
/// the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute" /> to the class.</summary>
Expand Down
4 changes: 3 additions & 1 deletion src/NodaMoney/CurrencyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ public static Currency Unregister(string code, string @namespace)
//// <exception cref="InvalidOperationException">The current CurrencyBuilder object has a property that must be set before the currency can be registered.</exception>
public Currency Build()
{
// TODO: Add validation?
// throw new InvalidOperationException("The current CurrencyBuilder object has a property that must be set before the currency can be registered.");
if (string.IsNullOrWhiteSpace(Symbol))
Symbol = Currency.CurrencySign;

var currency = new Currency(Code, ISONumber, DecimalDigits, EnglishName, Symbol, Namespace, ValidTo, ValidFrom);

return currency;
Expand Down
Loading

0 comments on commit 2c4b3d8

Please sign in to comment.