-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCustomEx.cs
More file actions
112 lines (90 loc) · 3.19 KB
/
CustomEx.cs
File metadata and controls
112 lines (90 loc) · 3.19 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Threading;
namespace PoeTradeSearch
{
// Custom Extensions
internal static class CustomEx
{
#region String Extensions
public static bool IsEmpty(this string owner, bool orNull = true)
{
return orNull ? string.IsNullOrEmpty(owner) : owner == "";
}
public static bool WithIn(this string owner, params string[] args)
{
return owner != null && Array.Exists(args, x => x.Equals(owner));
}
public static bool WithIn(this string owner, double minimum, double maximum)
{
return !owner.IsEmpty() && double.Parse(owner).WithIn(minimum, maximum);
}
public static int ToInt(this string owner, int @default = 0)
{
try
{
return owner.IsEmpty() ? @default : int.Parse(owner);
}
catch
{
return 0;
}
}
public static double ToDouble(this string owner, double @default = 0)
{
return owner.IsEmpty() ? @default : double.Parse(owner);
}
public static string ToTitleCase(this string owner)
{
if (owner == null) return owner;
string[] words = owner.Split(' ');
for (int i = 0; i < words.Length; i++)
{
if (words[i].Length == 0) continue;
words[i] = char.ToUpper(words[i][0])
+ (words[i].Length > 1 ? words[i].Substring(1).ToLower() : "");
}
return string.Join(" ", words);
}
public static string RepEx(this string owner, string pattern, string replacement)
{
return System.Text.RegularExpressions.Regex.Replace(owner, pattern, replacement);
}
public static string Escape(this string owner)
{
return System.Text.RegularExpressions.Regex.Escape(owner);
}
#endregion
#region Strings Extensions
public static string Join(this string[] owner, string separator)
{
return owner.Length > 1 ? string.Join(separator, owner) : owner[0];
}
public static string Join(this string[] owner, char separator)
{
return owner.Length > 1 ? string.Join(separator.ToString(), owner) : owner[0];
}
public static string Value(this string[] owner, int index, string @default = null)
{
return owner.Length > index ? owner[index] : @default;
}
#endregion
#region Number Extensions
public static bool WithIn(this double owner, double minimum, double maximum)
{
return owner >= minimum && owner <= maximum;
}
#endregion
#region Array Extensions
public static void ForEach<T>(this IEnumerable<T> ie, Action<T> action)
{
foreach (var i in ie) action(i);
}
#endregion
public static void BInvoke(this FrameworkElement sender, Delegate method)
{
sender.Dispatcher.BeginInvoke(DispatcherPriority.Background, method);
}
}
}