-
-
Notifications
You must be signed in to change notification settings - Fork 747
Expand file tree
/
Copy pathExtensions.cs
More file actions
90 lines (75 loc) · 2.38 KB
/
Extensions.cs
File metadata and controls
90 lines (75 loc) · 2.38 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
using System.Globalization;
using System.Text.RegularExpressions;
using System;
using ElectronNET.Runtime.Data;
using ElectronNET.Runtime.Services;
namespace ElectronNET.Common
{
internal static class Extensions
{
public static bool IsUnpackaged(this StartupMethod method)
{
switch (method)
{
case StartupMethod.UnpackedElectronFirst:
case StartupMethod.UnpackedDotnetFirst:
return true;
default:
return false;
}
}
public static string LowerFirst(this string str)
{
if (string.IsNullOrWhiteSpace(str))
{
return str;
}
if (str.Length == 1)
{
return str.ToLower();
}
return char.ToLower(str[0]) + str.Substring(1);
}
public static string StripAsync(this string str)
{
if (string.IsNullOrWhiteSpace(str))
{
return str;
}
var pos = str.LastIndexOf("Async", StringComparison.Ordinal);
if (pos > 0)
{
return str.Substring(0, pos);
}
return str;
}
public static string StripOn(this string str)
{
if (string.IsNullOrWhiteSpace(str) || !str.StartsWith("On", StringComparison.Ordinal))
{
return str;
}
return str.Substring(2);
}
public static string ToDashedEventName(this string str)
{
return string.Join("-", Regex.Split(str.StripOn(), "(?<!^)(?=[A-Z])")).ToLower(CultureInfo.InvariantCulture);
}
public static string ToCamelCaseEventName(this string str)
{
return str.StripOn().LowerFirst();
}
public static bool IsReady(this LifetimeServiceBase service)
{
return service != null && service.State == LifetimeState.Ready;
}
public static bool IsNotStopped(this LifetimeServiceBase service)
{
return service != null && service.State != LifetimeState.Stopped;
}
public static bool IsNullOrStopped(this LifetimeServiceBase service)
{
return service == null || service.State == LifetimeState.Stopped;
}
}
}