-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathReplacement.cs
More file actions
29 lines (22 loc) · 931 Bytes
/
Replacement.cs
File metadata and controls
29 lines (22 loc) · 931 Bytes
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
using System.Text.RegularExpressions;
namespace JavaToCSharp;
public class Replacement(string pattern, string replacement, RegexOptions options = RegexOptions.None)
{
public Regex Regex { get; } = new(pattern, options);
public string? ReplacementValue { get; } = replacement;
public string Replace(string input)
=> string.IsNullOrWhiteSpace(ReplacementValue)
? string.Empty
: Regex.Replace(input, ReplacementValue);
protected bool Equals(Replacement other)
=> 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()
=> HashCode.Combine(Regex, ReplacementValue);
}