/
FieldDefinition.cs
70 lines (59 loc) · 1.89 KB
/
FieldDefinition.cs
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;
namespace Examine
{
/// <summary>
/// Defines a field to be indexed
/// </summary>
public struct FieldDefinition : IEquatable<FieldDefinition>
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="name"></param>
/// <param name="type"></param>
public FieldDefinition(string name, string type)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("Value cannot be null or whitespace.", nameof(name));
}
if (string.IsNullOrWhiteSpace(type))
{
throw new ArgumentException("Value cannot be null or whitespace.", nameof(type));
}
Name = name;
Type = type;
}
/// <summary>
/// The name of the index field
/// </summary>
public string Name { get; }
/// <summary>
/// The data type
/// </summary>
public string Type { get; }
/// <inheritdoc/>
public bool Equals(FieldDefinition other) => string.Equals(Name, other.Name) && string.Equals(Type, other.Type);
/// <inheritdoc/>
public override bool Equals(object? obj)
{
if (obj is null)
{
return false;
}
return obj is FieldDefinition definition && Equals(definition);
}
/// <inheritdoc/>
public override int GetHashCode()
{
unchecked
{
return (Name.GetHashCode() * 397) ^ Type.GetHashCode();
}
}
/// <inheritdoc/>
public static bool operator ==(FieldDefinition left, FieldDefinition right) => left.Equals(right);
/// <inheritdoc/>
public static bool operator !=(FieldDefinition left, FieldDefinition right) => !left.Equals(right);
}
}