forked from sergiisyrovatchenko/SQLIndexManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
64 lines (50 loc) · 1.75 KB
/
Copy pathUtils.cs
File metadata and controls
64 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.ComponentModel;
namespace SQLIndexManager {
public static class Utils {
public static string ToDescription(this Enum value) {
var da = (DescriptionAttribute[])(value.GetType().GetField(value.ToString())).GetCustomAttributes(typeof(DescriptionAttribute), false);
return da.Length > 0 ? da[0].Description : value.ToString();
}
public static bool IsBetween(this int value, int minimum, int maximum) {
return value >= minimum && value <= maximum;
}
public static string ToQuota(this string value) {
return value?.Replace("[", "[[")
.Replace("]", "]]");
}
public static string Truncate(this string value, int maxLength) {
if (string.IsNullOrEmpty(value)) return value;
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
}
public static int PageSize(this int val) {
return val * 1024 / 8;
}
public static string FormatSize(this decimal val) {
decimal aval = Math.Abs(val);
string dimension = "KB";
if (aval > 1024 * 1024 * 1024) {
val = val / 1024 / 1024 / 1024;
dimension = "TB";
}
else if (aval > 1024 * 1024) {
val = val / 1024 / 1024;
dimension = "GB";
}
else if (aval > 1024) {
val = val / 1024;
dimension = "MB";
}
return $"{ (val.ToString(val - Math.Truncate(val) == 0 ? "N0" : "N2")) } {dimension}";
}
public static string FormatMbSize(this int val) {
decimal value = val;
string dimension = "MB";
if (value > 1000) {
value = value / 1024;
dimension = "GB";
}
return $"{ (value.ToString(value - Math.Truncate(value) == 0 ? "N0" : "N2")) } {dimension}";
}
}
}