コード例 #1
0
        /// <summary>
        /// Initializes static members of the <see cref="DynamicQuantity"/> struct.
        /// </summary>
        static DynamicQuantity()
        {
            var up = new DynamicUnitProvider();

            up.Register(typeof(SI));
            UnitProvider = up;
        }
コード例 #2
0
        public void ToString_UnitProvider()
        {
            var up = new DynamicUnitProvider(CultureInfo.InvariantCulture, typeof(SI));

            var speed = 10 * SI.Metre / SI.Second;
            Assert.AreEqual("10 m/s", speed.ToString(up));
        }
コード例 #3
0
        public void ToString_SetDisplayUnit()
        {
            var up = new DynamicUnitProvider(CultureInfo.InvariantCulture);
            up.Register(typeof(SI));
            up.SetDisplayUnit("km/h", SI.KilometrePerHour);

            var speed = 10 * SI.Metre / SI.Second;
            Assert.AreEqual("36 km/h", speed.ToString(up));
        }
コード例 #4
0
        public void Parse_Speed()
        {
            var up = new DynamicUnitProvider(CultureInfo.InvariantCulture, typeof(SI));

            var speed = DynamicQuantity.Parse("3.6 km/h", up);
            Assert.AreEqual(1, speed.Value);
            Assert.AreEqual(1, speed.Dimensions.Length);
            Assert.AreEqual(-1, speed.Dimensions.Time);
        }