Fauna v10 .NET/C# Driver 1.0.1
 
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
23 Unwrap = v;
24 }
25
31 public override void Serialize(MappingContext ctx, Utf8FaunaWriter writer)
32 {
33 writer.WriteStartObject();
34 writer.WriteFieldName("value");
35 var ser = Unwrap is not null ? Serializer.Generate(ctx, Unwrap.GetType()) : DynamicSerializer.Singleton;
36 ser.Serialize(ctx, writer, Unwrap);
37 writer.WriteEndObject();
38 }
39
45 public override bool Equals(Query? o) => IsEqual(o as QueryVal);
46
52 public override bool Equals(object? o)
53 {
54 if (ReferenceEquals(this, o))
55 {
56 return true;
57 }
58
59 return IsEqual(o as QueryVal);
60 }
61
66 public override int GetHashCode()
67 {
68 var hash = 31;
69
70 if (Unwrap is not null)
71 {
72 hash *= Unwrap.GetHashCode();
73 }
74
75 return hash;
76 }
77
82 public override string ToString() => $"QueryVal({Unwrap})";
83
90 public static bool operator ==(QueryVal left, QueryVal right)
91 {
92 if (ReferenceEquals(left, right))
93 {
94 return true;
95 }
96
97 if (left is null || right is null)
98 {
99 return false;
100 }
101
102 return left.Equals(right);
103 }
104
111 public static bool operator !=(QueryVal left, QueryVal right)
112 {
113 return !(left == right);
114 }
115
116 private bool IsEqual(QueryVal? o)
117 {
118 if (o is null)
119 {
120 return false;
121 }
122
123 if (Unwrap is null)
124 {
125 return (o.Unwrap is null) ? true : false;
126 }
127
128 return Unwrap.Equals(o.Unwrap);
129 }
130}
A class representing the mapping context to be used during serialization and deserialization.
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:31
override bool Equals(object? o)
Determines whether the specified object is equal to the current QueryVal.
Definition QueryVal.cs:52
static bool operator!=(QueryVal left, QueryVal right)
Determines whether two specified instances of QueryVal are not equal.
Definition QueryVal.cs:111
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:66
static bool operator==(QueryVal left, QueryVal right)
Determines whether two specified instances of QueryVal are equal.
Definition QueryVal.cs:90
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.