Fauna v10 .NET/C# Driver 0.2.0-beta
 
Loading...
Searching...
No Matches
QueryExpr.cs
Go to the documentation of this file.
1using System.Collections.ObjectModel;
2using Fauna.Mapping;
4
5namespace Fauna;
6
10public sealed class QueryExpr : Query, IQueryFragment
11{
16 public QueryExpr(IList<IQueryFragment> fragments)
17 {
18 Unwrap = new ReadOnlyCollection<IQueryFragment>(fragments);
19 }
20
25 public QueryExpr(params IQueryFragment[] fragments)
26 : this(fragments.ToList())
27 {
28 }
29
33 public IReadOnlyCollection<IQueryFragment> Unwrap { get; }
34
38 public IReadOnlyCollection<IQueryFragment> Fragments => Unwrap;
39
45 public override void Serialize(MappingContext ctx, Utf8FaunaWriter writer)
46 {
47 writer.WriteStartObject();
48 writer.WriteFieldName("fql");
49 writer.WriteStartArray();
50 foreach (var t in Unwrap)
51 {
52 t.Serialize(ctx, writer);
53 }
54 writer.WriteEndArray();
55 writer.WriteEndObject();
56 }
57
63 public override bool Equals(Query? o) => IsEqual(o as QueryExpr);
64
70 public override bool Equals(object? o)
71 {
72 if (ReferenceEquals(this, o))
73 {
74 return true;
75 }
76
77 return o is QueryExpr expr && IsEqual(expr);
78 }
79
84 public override int GetHashCode() => Fragments.GetHashCode();
85
90 public override string ToString() => $"QueryExpr({string.Join(",", Fragments)})";
91
92 private bool IsEqual(QueryExpr? o)
93 {
94 if (o is null)
95 {
96 return false;
97 }
98
99 if (Fragments == null || o.Fragments == null)
100 {
101 return Fragments == null && o.Fragments == null;
102 }
103
104 return Fragments.SequenceEqual(o.Fragments);
105 }
106
113 public static bool operator ==(QueryExpr left, QueryExpr right)
114 {
115 if (ReferenceEquals(left, right))
116 {
117 return true;
118 }
119
120 if (left is null || right is null)
121 {
122 return false;
123 }
124
125 return left.Equals(right);
126 }
127
134 public static bool operator !=(QueryExpr left, QueryExpr right)
135 {
136 return !(left == right);
137 }
138}
A class representing the mapping context to be used during serialization and deserialization.
Represents an FQL query expression. This class encapsulates a list of IQueryFragment instances,...
Definition QueryExpr.cs:11
override bool Equals(object? o)
Determines whether the specified object is equal to the current QueryExpr.
Definition QueryExpr.cs:70
IReadOnlyCollection< IQueryFragment > Unwrap
Gets the readonly collection of query fragments.
Definition QueryExpr.cs:33
QueryExpr(params IQueryFragment[] fragments)
Initializes a new instance of the QueryExpr class with one or more query fragments.
Definition QueryExpr.cs:25
override bool Equals(Query? o)
Determines whether the specified QueryExpr is equal to the current QueryExpr.
override string ToString()
Returns a string that represents the current QueryExpr.
override void Serialize(MappingContext ctx, Utf8FaunaWriter writer)
Serializes the query expression.
Definition QueryExpr.cs:45
QueryExpr(IList< IQueryFragment > fragments)
Initializes a new instance of the QueryExpr class with a collection of query fragments.
Definition QueryExpr.cs:16
static bool operator==(QueryExpr left, QueryExpr right)
Determines whether two specified instances of QueryExpr are equal.
Definition QueryExpr.cs:113
static bool operator!=(QueryExpr left, QueryExpr right)
Determines whether two specified instances of QueryExpr are not equal.
Definition QueryExpr.cs:134
IReadOnlyCollection< IQueryFragment > Fragments
Gets the readonly collection of query fragments.
Definition QueryExpr.cs:38
override int GetHashCode()
The default hash function.
Represents the abstract base class for constructing FQL queries.
Definition Query.cs:11
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 WriteStartArray()
Writes the beginning of an array.
void WriteStartObject()
Writes the beginning of an object.
Represents the base interface for a query fragment used for FQL query construction.
Definition Client.cs:8