1
0
mirror of https://github.com/chylex/Query.git synced 2025-08-30 00:53:09 +02:00
Files
AppCalc
AppConv
General
Properties
Units
Angle.cs
Area.cs
Length.cs
Radix.cs
Storage.cs
Temperature.cs
Volume.cs
Weight.cs
Utils
App.cs
AppConv.csproj
AppMeme
AppWindows
Base
Query
.gitignore
Query.sln
icon.ico
Query/AppConv/Units/Storage.cs
2024-07-29 16:57:33 +02:00

30 lines
1.1 KiB
C#

using System;
using AppConv.General;
using AppConv.Utils;
namespace AppConv.Units {
internal class Storage : DecimalUnitConverterSimple<Storage.Units>{
internal enum Units{
Invalid = 0, Byte, Bit
}
public Storage(){
AddUnit(Units.Byte, "B", "byte", "bytes");
AddUnit(Units.Bit, "b", "bit", "bits");
SetUnitFactor(Units.Bit, 8M);
SetInvalidUnitObject(Units.Invalid);
SI.ExtededProperties bitConversionProperties = new SI.ExtededProperties{
FactorPredicate = factor => factor > 0 && factor%3 == 0,
FromFunctionGenerator = exponent => () => (decimal)Math.Pow(1024, -(int)(exponent/3)),
ToFunctionGenerator = exponent => () => (decimal)Math.Pow(1024, (int)(exponent/3))
};
SI.AddSupportCustom(typeof(Units), Units.Byte, new []{ "B" }, new []{ "byte", "bytes" }, ConvertFrom, ConvertTo, Names, bitConversionProperties);
SI.AddSupportCustom(typeof(Units), Units.Bit, new []{ "b" }, new []{ "bit", "bits" }, ConvertFrom, ConvertTo, Names, bitConversionProperties);
}
}
}