forked from paulirwin/JavaToCSharp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReplacement.cs
More file actions
39 lines (31 loc) · 1.11 KB
/
Copy pathReplacement.cs
File metadata and controls
39 lines (31 loc) · 1.11 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
using System.Text.RegularExpressions;
namespace JavaToCSharp;
public class Replacement
{
public Replacement(string pattern, string replacement, RegexOptions options = RegexOptions.None)
{
Regex = new Regex(pattern, options);
ReplacementValue = replacement;
}
public Regex? Regex { get; }
public string? ReplacementValue { get; }
public string? Replace(string input) => System.String.IsNullOrWhiteSpace(ReplacementValue) ? null : Regex?.Replace(input, ReplacementValue);
protected bool Equals(Replacement other)
{
return Equals(Regex, other.Regex) && ReplacementValue == other.ReplacementValue;
}
public override bool Equals(object? obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((Replacement) obj);
}
public override int GetHashCode()
{
unchecked
{
return ((Regex != null ? Regex.GetHashCode() : 0) * 397) ^ (ReplacementValue != null ? ReplacementValue.GetHashCode() : 0);
}
}
}