Click here to Skip to main content
15,891,184 members
Articles / DevOps / Unit Testing

Units of Measure Library for .NET

Rate me:
Please Sign up or sign in to vote.
4.93/5 (7 votes)
20 Jun 2012CPOL8 min read 60.4K   2K   35  
This article introduces a library for handling units of measure.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HDLibrary.UnitsOfMeasure
{
    /// <summary>
    /// Defines a new unit
    /// </summary>
    [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
    public sealed class UnitDefinitionAttribute : Attribute
    {
        /// <summary>
        /// Defines a new base unit
        /// </summary>
        /// <param name="unitAbbr">The abbreviation of the unit, e.g. "m"</param>
        /// <param name="unitName">The name of the unit, e.g. "Meter"</param>
        public UnitDefinitionAttribute(string unitAbbr, string unitName)
        {
            UnitAbbr = unitAbbr;
            UnitName = unitName;
            Definition = null;
        }

        /// <summary>
        /// Defines a new scaled, shifted or derived unit
        /// </summary>
        /// <param name="unitAbbr">The abbreviation of the unit, e.g. "m"</param>
        /// <param name="unitName">The name of the unit, e.g. "Meter"</param>
        /// <param name="definition">The definition, e.g. "1000 m" or "m / s"</param>
        public UnitDefinitionAttribute(string unitAbbr, string unitName, string definition)
        {
            UnitAbbr = unitAbbr;
            UnitName = unitName;
            Definition = definition;
        }

        public string UnitAbbr { get; private set; }
        public string UnitName { get; private set; }
        public string Definition { get; private set; }
    }
}

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 Code Project Open License (CPOL)


Written By
Student
Germany Germany
Presently I am a student of computer science at the Karlsruhe Institute of Technology in Germany.

Comments and Discussions