-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensions.cs
More file actions
51 lines (42 loc) · 1.33 KB
/
Extensions.cs
File metadata and controls
51 lines (42 loc) · 1.33 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
using System;
using System.IO;
using System.Text;
namespace UpdateAssemblyInfo
{
public static class Extensions
{
public static bool EqualsIgnoreCase(this string str, string text, bool trim = false)
{
if (trim)
{
str = str.Nullify();
text = text.Nullify();
}
if (str == null)
return text == null;
if (text == null)
return false;
if (str.Length != text.Length)
return false;
return string.Compare(str, text, StringComparison.OrdinalIgnoreCase) == 0;
}
public static string Nullify(this string str)
{
if (str == null)
return null;
if (string.IsNullOrWhiteSpace(str))
return null;
var t = str.Trim();
return t.Length == 0 ? null : t;
}
public static Encoding DetectFileEncoding(string filePath, Encoding defaultEncodingIfNoBom = null)
{
defaultEncodingIfNoBom = defaultEncodingIfNoBom ?? Encoding.Default;
using (var reader = new StreamReader(filePath, defaultEncodingIfNoBom, true))
{
reader.Peek();
return reader.CurrentEncoding;
}
}
}
}