Channel9Downloader.Converters.BytesPerSecondToDisplayValueConverter.Convert C# (CSharp) 메소드

Convert() 공개 메소드

Converts a double value in seconds to a more readable string representation.
public Convert ( object value, Type targetType, object parameter, CultureInfo culture ) : object
value object The value produced by the binding source.
targetType System.Type The type of the binding target property.
parameter object The converter parameter to use.
culture System.Globalization.CultureInfo The culture to use in the converter.
리턴 object
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var bytes = (double)value;

            if (bytes == 0)
            {
                return string.Empty;
            }

            if (bytes > 1000000000)
            {
                var gigs = bytes / 1000000000.0;
                return string.Format("{0:0.00} GB/s", gigs); // Yeah, I wish...
            }

            if (bytes > 1000000)
            {
                var megs = bytes / 1000000.0;
                return string.Format("{0:0.00} MB/s", megs);
            }

            if (bytes > 1000)
            {
                var kilos = bytes / 1000.0;
                return string.Format("{0:0.00} KB/s", kilos);
            }

            return string.Format("{0} Bytes/s", bytes);
        }
BytesPerSecondToDisplayValueConverter