-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathPostgresFacets.cs
More file actions
70 lines (55 loc) · 1.78 KB
/
PostgresFacets.cs
File metadata and controls
70 lines (55 loc) · 1.78 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
using System;
using System.Text;
namespace Npgsql.PostgresTypes;
readonly struct PostgresFacets : IEquatable<PostgresFacets>
{
internal static readonly PostgresFacets None = new(null, null, null);
internal PostgresFacets(int? size, int? precision, int? scale)
{
Size = size;
Precision = precision;
Scale = scale;
}
public readonly int? Size;
public readonly int? Precision;
public readonly int? Scale;
public override bool Equals(object? o)
=> o is PostgresFacets otherFacets && Equals(otherFacets);
public bool Equals(PostgresFacets o)
=> Size == o.Size && Precision == o.Precision && Scale == o.Scale;
public static bool operator ==(PostgresFacets x, PostgresFacets y) => x.Equals(y);
public static bool operator !=(PostgresFacets x, PostgresFacets y) => !(x == y);
public override int GetHashCode()
{
var hashcode = Size?.GetHashCode() ?? 0;
hashcode = (hashcode * 397) ^ (Precision?.GetHashCode() ?? 0);
hashcode = (hashcode * 397) ^ (Scale?.GetHashCode() ?? 0);
return hashcode;
}
public override string ToString()
{
if (Size == null && Precision == null && Scale == null)
return string.Empty;
var sb = new StringBuilder().Append('(');
var needComma = false;
if (Size != null)
{
sb.Append(Size);
needComma = true;
}
if (Precision != null)
{
if (needComma)
sb.Append(", ");
sb.Append(Precision);
needComma = true;
}
if (Scale != null)
{
if (needComma)
sb.Append(", ");
sb.Append(Scale);
}
return sb.Append(')').ToString();
}
}