Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Money type for the CLR

, 18 Mar 2013
A convenient, high-performance money structure for the CLR which handles arithmetic operations, currency types, formatting, and careful distribution and rounding without loss.
moneytype.zip
Money
lib
xunit.console.clr4.exe
xunit.console.clr4.x86.exe
xunit.console.exe
xunit.console.x86.exe
xunit.dll
xunit.dll.tdnet
xunit.extensions.dll
xunit.gui.clr4.exe
xunit.gui.clr4.x86.exe
xunit.gui.exe
xunit.gui.x86.exe
xunit.installer.exe
xunit.runner.msbuild.dll
xunit.runner.tdnet.dll
xunit.runner.utility.dll
xunitext.dll
xunitext.nunit.dll
xunitext.runner.jetbrains.dll
xunitext.runner.msbuild.dll
xunitext.runner.tdnet.dll
xunitext35.dll
src
Money.sln.DotSettings.user
Money.Tests
bin
Debug
Money.dll
Money.Tests.dll
xunit.dll
obj
Debug
Money.Tests.dll
Properties
Money.v11.suo
Money
bin
Debug
Money.dll
obj
Debug
Money.dll
Properties
using System;
using System.Runtime.Serialization;

namespace System
{
    [Serializable]
    public class MoneyAllocationException : Exception
    {
        private readonly Money _amountToDistribute;
        private readonly Money _distributionTotal;
        private readonly Decimal[] _distribution;

        public MoneyAllocationException(Money amountToDistribute,
                                        Money distributionTotal,
                                        Decimal[] distribution)
        {
            _amountToDistribute = amountToDistribute;
            _distribution = distribution;
            _distributionTotal = distributionTotal;
        }

        public MoneyAllocationException(Money amountToDistribute,
                                        Money distributionTotal,
                                        Decimal[] distribution,
                                        String message)
            : base(message)
        {
            _amountToDistribute = amountToDistribute;
            _distribution = distribution;
            _distributionTotal = distributionTotal;
        }

        public MoneyAllocationException(Money amountToDistribute,
                                        Money distributionTotal,
                                        Decimal[] distribution,
                                        String message,
                                        Exception inner)
            : base(message, inner)
        {
            _amountToDistribute = amountToDistribute;
            _distribution = distribution;
            _distributionTotal = distributionTotal;
        }

        protected MoneyAllocationException(SerializationInfo info,
                                           StreamingContext context)
            : base(info, context)
        {
            _amountToDistribute = (Money)info.GetValue("_amountToDistribute",
                                                       typeof(Money));
            _distributionTotal = (Money)info.GetValue("_distributionTotal",
                                                      typeof(Money));
            _distribution = (Decimal[])info.GetValue("_distribution",
                                                     typeof(Decimal[]));
        }

        public Decimal[] Distribution
        {
            get { return _distribution; }
        }

        public Money DistributionTotal
        {
            get { return _distributionTotal; }
        }

        public Money AmountToDistribute
        {
            get { return _amountToDistribute; }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

codekaizen
Architect
United States United States
I'm a software engineer with 25 years of experience in areas from game and simulation development, enterprise development, systems management, machine learning, real-time and embedded systems development and geospaitial systems development.
 
You can find more of my work at http://www.codeplex.com and my articles at http://vectordotnet.blogspot.com/ and http://dotnoted.spaces.live.com.

| Advertise | Privacy | Mobile
Web02 | 2.8.140826.1 | Last Updated 18 Mar 2013
Article Copyright 2008 by codekaizen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid