Пример #1
0
        public void ToString_Unit_Test(long length, ByteSizeUnit unit, string expectedValue)
        {
            var byteSize       = new ByteSize(length);
            var formattedValue = byteSize.ToString(unit, CultureInfo.InvariantCulture);

            Assert.Equal(expectedValue, formattedValue);
        }
Пример #2
0
 /// <summary>
 /// Gets the <see cref="double" /> value that represents the value of this instance in accordance to the <paramref name="unit" /> parameter.
 /// </summary>
 /// <param name="unit">The <see cref="ByteSizeUnit" /> to convert the value of this instance to.</param>
 /// <returns>
 /// A <see cref="double" /> value representing the value of this instance in accordance to the <paramref name="unit" /> parameter.
 /// </returns>
 public double GetNumberForUnit(ByteSizeUnit unit)
 {
     return(unit switch
     {
         ByteSizeUnit.Byte => Bytes,
         ByteSizeUnit.KiloByte => KiloBytes,
         ByteSizeUnit.MegaByte => MegaBytes,
         ByteSizeUnit.GigaByte => GigaBytes,
         ByteSizeUnit.TeraByte => TeraBytes,
         ByteSizeUnit.PetaByte => PetaBytes,
         ByteSizeUnit.ExaByte => ExaBytes,
         _ => throw Throw.InvalidEnumArgument(nameof(unit), unit)
     });
Пример #3
0
        private static void GenerateUnit(int count, ByteSizeUnit unit, bool isUpper, StringBuilder output)
        {
            var text = s_unitText[unit];

            switch (count)
            {
            case 1: output.Append(isUpper ? text.UpperText1 : text.LowerText1); break;

            case 2: output.Append(isUpper ? text.UpperText2 : text.LowerText2); break;

            case 3: output.Append(isUpper ? text.UpperText3 : text.LowerText3); break;
            }
            ;
        }
Пример #4
0
 public string ToString(ByteSizeUnit unit, IFormatProvider?formatProvider) => GetValue(unit).ToString(formatProvider) + UnitToString(unit);
Пример #5
0
 public string ToString(ByteSizeUnit unit) => ToString(unit, formatProvider: null);