Fauna .NET Driver 0.1.0-beta
 
Loading...
Searching...
No Matches
QueryVal.cs
Go to the documentation of this file.
1using Fauna.Mapping;
3
4namespace Fauna;
5
9public sealed class QueryVal : Query, IQueryFragment
10{
14 public object? Unwrap { get; }
15
20 public QueryVal(object? v)
21 {
22 Unwrap = v;
23 }
24
30 public override void Serialize(MappingContext ctx, Utf8FaunaWriter writer)
31 {
32 writer.WriteStartObject();
33 writer.WriteFieldName("value");
34 Serializer.Serialize(ctx, writer, Unwrap);
35 writer.WriteEndObject();
36 }
37
43 public override bool Equals(Query? o) => IsEqual(o as QueryVal);
44
50 public override bool Equals(object? o)
51 {
52 if (ReferenceEquals(this, o))
53 {
54 return true;
55 }
56
57 return IsEqual(o as QueryVal);
58 }
59
64 public override int GetHashCode()
65 {
66 var hash = 31;
67
68 if (Unwrap is not null)
69 {
70 hash *= Unwrap.GetHashCode();
71 }
72
73 return hash;
74 }
75
80 public override string ToString() => $"QueryVal({Unwrap})";
81
88 public static bool operator ==(QueryVal left, QueryVal right)
89 {
90 if (ReferenceEquals(left, right))
91 {
92 return true;
93 }
94
95 if (left is null || right is null)
96 {
97 return false;
98 }
99
100 return left.Equals(right);
101 }
102
109 public static bool operator !=(QueryVal left, QueryVal right)
110 {
111 return !(left == right);
112 }
113
114 private bool IsEqual(QueryVal? o)
115 {
116 if (o is null)
117 {
118 return false;
119 }
120
121 if (Unwrap is null)
122 {
123 return (o.Unwrap is null) ? true : false;
124 }
125
126 return Unwrap.Equals(o.Unwrap);
127 }
128}
Represents the abstract base class for constructing FQL queries.
Definition Query.cs:11
Represents a generic value holder for FQL queries. This class allows embedding values of various type...
Definition QueryVal.cs:10
override void Serialize(MappingContext ctx, Utf8FaunaWriter writer)
Serializes the query value.
Definition QueryVal.cs:30
override bool Equals(object? o)
Determines whether the specified object is equal to the current QueryVal.
Definition QueryVal.cs:50
static bool operator!=(QueryVal left, QueryVal right)
Determines whether two specified instances of QueryVal are not equal.
Definition QueryVal.cs:109
override bool Equals(Query? o)
Determines whether the specified QueryVal is equal to the current QueryVal.
override int GetHashCode()
The default hash function.
Definition QueryVal.cs:64
static bool operator==(QueryVal left, QueryVal right)
Determines whether two specified instances of QueryVal are equal.
Definition QueryVal.cs:88
QueryVal(object? v)
Initializes a new instance of the QueryVal class with the specified value.
Definition QueryVal.cs:20
object? Unwrap
Gets the value of the specified type represented in the query.
Definition QueryVal.cs:14
override string ToString()
Returns a string that represents the current QueryVal.
Provides functionality for writing data in a streaming manner to a buffer or a stream.
void WriteFieldName(string value)
Writes a field name for the next value.
void WriteEndObject()
Writes the end of an object.
void WriteStartObject()
Writes the beginning of an object.
Represents the base interface for a query fragment used for FQL query construction.
Definition Client.cs:9