예제 #1
0
 public ScaleBuilder(UnitConfiguration config, UnitMeta rootUnit)
 {
     this.config   = config;
     precedingUnit = rootUnit;
     if (rootUnit.PhysicalUnit.IsDimensionless())
     {
         throw new InvalidOperationException("The unit you start with should be associated with a physical unit to start a scale.");
     }
 }
예제 #2
0
        IUnitScale IUnitScale.To(Unit singleUnit, int scale)
        {
            var newUnit = config.Unit(singleUnit)
                          .IsPhysicalUnit(precedingUnit.PhysicalUnit)
                          .ConvertValueBased(precedingUnit.Unit, v => v * scale, v => v / scale);

            ((IUnitMetaConfig)precedingUnit).ConvertValueBased(singleUnit, v => v / scale, v => v * scale);
            precedingUnit = (UnitMeta)newUnit;
            return(this);
        }