private static string ToMbGb(double amount, bool includeUnit = true, ByteTypes byteType = ByteTypes.Auto) { var neg = false; if (amount < 0) { amount *= -1; neg = true; } var numDiv = 0; while ((amount >= 1024.0 || byteType != ByteTypes.Auto) && numDiv < (int)(byteType == ByteTypes.Auto ? ByteTypes.TB : byteType)) { amount /= 1024.0; numDiv++; } var result = amount.ToString("0.00"); if (includeUnit) { result += " " + Enum.Parse(typeof(ByteTypes), numDiv.ToString(CultureInfo.InvariantCulture)); } if (neg) { result = result.StartsWith("-") ? result.Substring(1) : "-" + result; } return(result); }
public static Type GetModelType(byte constType) { if (ByteTypes.ContainsKey(constType)) { return(ByteTypes[constType]); } return(null); }
public static string GetName(byte constType) { if (ByteTypes.ContainsKey(constType)) { var type = ByteTypes[constType]; if (type != null) { return(type.Name); } } return(string.Empty); }