コード例 #1
0
        public Acceleration WithDenominatorUnit(SquareTimeUnit newUnit)
        {
            // generator : FractionValuesGenerator.Add_WithDenominatorUnit
            var oldUnit = Unit.DenominatorUnit;

            if (oldUnit == newUnit)
            {
                return(this);
            }
            var oldFactor  = GlobalUnitRegistry.Factors.GetThrow(oldUnit);
            var newFactor  = GlobalUnitRegistry.Factors.GetThrow(newUnit);
            var resultUnit = Unit.WithDenominatorUnit(newUnit);

            return(new Acceleration(newFactor / oldFactor * Value, resultUnit));
        }
コード例 #2
0
        public static Acceleration Parse(string value)
        {
            // generator : FractionValuesGenerator.Add_Parse
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(nameof(value));
            }
            var r     = CommonParse.Parse(value, typeof(Acceleration));
            var units = Common.SplitUnitNameBySlash(r.UnitName);

            if (units.Length != 2)
            {
                throw new Exception($"{r.UnitName} is not valid Acceleration unit");
            }
            var counterUnit     = new LengthUnit(units[0]);
            var denominatorUnit = new SquareTimeUnit(units[1]);

            return(new Acceleration(r.Value, counterUnit, denominatorUnit));
        }
コード例 #3
0
 public Acceleration(decimal value, LengthUnit counterUnit, SquareTimeUnit denominatorUnit)
 {
     Value = value;
     Unit  = new AccelerationUnit(counterUnit, denominatorUnit);
 }