Convert if to switch statement.

This commit is contained in:
2022-11-13 19:38:02 +00:00
parent d7577c9880
commit 02d6222ae9
13 changed files with 752 additions and 410 deletions

View File

@@ -421,14 +421,25 @@ public static partial class Decoders
result = (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2) * Math.Pow(2, csd.ReadBlockLength);
if(result > 1073741824)
sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
else if(result > 1048576)
sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
else if(result > 1024)
sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
else
sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
switch(result)
{
case > 1073741824:
sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
break;
case > 1048576:
sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
break;
case > 1024:
sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
break;
default:
sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
break;
}
switch(csd.ReadCurrentAtVddMin & 0x07)
{

View File

@@ -438,18 +438,27 @@ public static partial class Decoders
{
unit = Math.Pow(2, csd.OperationCodesTimeout) * 100;
if(unit > 1000000)
sb.
AppendFormat("\t\tMaximum timeout for switch command when setting a value to the mode operation codes field is {0:D2}s",
unit / 1000000).AppendLine();
else if(unit > 1000)
sb.
AppendFormat("\tMaximum timeout for switch command when setting a value to the mode operation codes field is {0:D2}ms",
unit / 1000).AppendLine();
else
sb.
AppendFormat("\tMaximum timeout for switch command when setting a value to the mode operation codes field is {0:D2}µs",
unit).AppendLine();
switch(unit)
{
case > 1000000:
sb.
AppendFormat("\t\tMaximum timeout for switch command when setting a value to the mode operation codes field is {0:D2}s",
unit / 1000000).AppendLine();
break;
case > 1000:
sb.
AppendFormat("\tMaximum timeout for switch command when setting a value to the mode operation codes field is {0:D2}ms",
unit / 1000).AppendLine();
break;
default:
sb.
AppendFormat("\tMaximum timeout for switch command when setting a value to the mode operation codes field is {0:D2}µs",
unit).AppendLine();
break;
}
}
}
@@ -716,43 +725,71 @@ public static partial class Decoders
{
unit = Math.Pow(2, csd.ProductionStateAwareness) * 100;
if(unit > 1000000)
sb.AppendFormat("\tDevice takes a maximum of {0} s to switch production state awareness",
unit / 1000000).AppendLine();
else if(unit > 1000)
sb.AppendFormat("\tDevice takes a maximum of {0} ms to switch production state awareness", unit / 1000).
AppendLine();
else
sb.AppendFormat("\tDevice takes a maximum of {0} μs to switch production state awareness", unit).
AppendLine();
switch(unit)
{
case > 1000000:
sb.AppendFormat("\tDevice takes a maximum of {0} s to switch production state awareness",
unit / 1000000).AppendLine();
break;
case > 1000:
sb.AppendFormat("\tDevice takes a maximum of {0} ms to switch production state awareness",
unit / 1000).AppendLine();
break;
default:
sb.AppendFormat("\tDevice takes a maximum of {0} μs to switch production state awareness", unit).
AppendLine();
break;
}
}
if(csd.SleepAwakeTimeout > 0)
{
unit = Math.Pow(2, csd.SleepAwakeTimeout) * 100;
if(unit > 1000000)
sb.AppendFormat("\tDevice takes a maximum of {0} ms to transition between sleep and standby states",
unit / 1000000).AppendLine();
else if(unit > 1000)
sb.AppendFormat("\tDevice takes a maximum of {0} μs to transition between sleep and standby states",
unit / 1000).AppendLine();
else
sb.AppendFormat("\tDevice takes a maximum of {0} ns to transition between sleep and standby states",
unit).AppendLine();
switch(unit)
{
case > 1000000:
sb.AppendFormat("\tDevice takes a maximum of {0} ms to transition between sleep and standby states",
unit / 1000000).AppendLine();
break;
case > 1000:
sb.AppendFormat("\tDevice takes a maximum of {0} μs to transition between sleep and standby states",
unit / 1000).AppendLine();
break;
default:
sb.AppendFormat("\tDevice takes a maximum of {0} ns to transition between sleep and standby states",
unit).AppendLine();
break;
}
}
if(csd.SleepNotificationTimeout > 0)
{
unit = Math.Pow(2, csd.SleepNotificationTimeout) * 10;
if(unit > 1000000)
sb.AppendFormat("\tDevice takes a maximum of {0} s to move to sleep state", unit / 1000000).
AppendLine();
else if(unit > 1000)
sb.AppendFormat("\tDevice takes a maximum of {0} ms to move to sleep state", unit / 1000).AppendLine();
else
sb.AppendFormat("\tDevice takes a maximum of {0} μs to move to sleep state", unit).AppendLine();
switch(unit)
{
case > 1000000:
sb.AppendFormat("\tDevice takes a maximum of {0} s to move to sleep state", unit / 1000000).
AppendLine();
break;
case > 1000:
sb.AppendFormat("\tDevice takes a maximum of {0} ms to move to sleep state", unit / 1000).
AppendLine();
break;
default:
sb.AppendFormat("\tDevice takes a maximum of {0} μs to move to sleep state", unit).AppendLine();
break;
}
}
sb.AppendFormat("\tDevice has {0} sectors", csd.SectorCount).AppendLine();