-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRequiredString.cs
More file actions
37 lines (23 loc) · 1.46 KB
/
Copy pathRequiredString.cs
File metadata and controls
37 lines (23 loc) · 1.46 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
using System;
namespace DataBoss.Data
{
[DbType(typeof(string), required: true)]
public struct RequiredString : IComparable<RequiredString>, IEquatable<RequiredString>
{
readonly string v;
public RequiredString(string value) { this.v = value ?? throw new ArgumentNullException(nameof(value)); }
public string Value => v ?? string.Empty;
public static explicit operator RequiredString(string value) => new RequiredString(value);
public static implicit operator string(RequiredString s) => s.Value;
public int CompareTo(RequiredString other) => this.Value.CompareTo(other.Value);
public bool Equals(RequiredString other) => this.Value.Equals(other.Value);
public override bool Equals(object obj) => obj is RequiredString other && Equals(other);
public override int GetHashCode() => Value.GetHashCode();
public static bool operator ==(RequiredString left, RequiredString right) => left.Equals(right);
public static bool operator !=(RequiredString left, RequiredString right) => !(left == right);
public static bool operator <(RequiredString left, RequiredString right) => left.CompareTo(right) < 0;
public static bool operator <=(RequiredString left, RequiredString right) => left.CompareTo(right) <= 0;
public static bool operator >(RequiredString left, RequiredString right) => left.CompareTo(right) > 0;
public static bool operator >=(RequiredString left, RequiredString right) => left.CompareTo(right) >= 0;
}
}