public static void WriteQueryResult <TResult, TInclude>(this BlittableJsonTextWriter writer, JsonOperationContext context, QueryResultBase <TResult, TInclude> result, bool metadataOnly, out int numberOfResults, bool partial = false)
        {
            if (partial == false)
            {
                writer.WriteStartObject();
            }

            writer.WritePropertyName(nameof(result.IndexName));
            writer.WriteString(result.IndexName);
            writer.WriteComma();

            var results = (object)result.Results;

            if (results is List <Document> documents)
            {
                writer.WritePropertyName(nameof(result.Results));
                writer.WriteDocuments(context, documents, metadataOnly, out numberOfResults);
                writer.WriteComma();
            }
            else if (results is List <BlittableJsonReaderObject> objects)
            {
                writer.WritePropertyName(nameof(result.Results));
                writer.WriteObjects(context, objects, out numberOfResults);
                writer.WriteComma();
            }
            else
            {
                throw new NotSupportedException($"Cannot write query result of '{typeof(TResult)}' type in '{result.GetType()}'.");
            }

            var includes = (object)result.Includes;

            if (includes is List <Document> includeDocuments)
            {
                writer.WritePropertyName(nameof(result.Includes));
                writer.WriteIncludes(context, includeDocuments);
                writer.WriteComma();
            }
            else if (includes is List <BlittableJsonReaderObject> includeObjects)
            {
                if (includeObjects.Count != 0)
                {
                    throw new NotSupportedException("Cannot write query includes of List<BlittableJsonReaderObject>, but got non zero response");
                }

                writer.WritePropertyName(nameof(result.Includes));
                writer.WriteStartObject();
                writer.WriteEndObject();
                writer.WriteComma();
            }
            else
            {
                throw new NotSupportedException($"Cannot write query includes of '{typeof(TInclude)}' type in '{result.GetType()}'.");
            }

            writer.WritePropertyName(nameof(result.IndexTimestamp));
            writer.WriteString(result.IndexTimestamp.ToString(Default.DateTimeFormatsToWrite));
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.LastQueryTime));
            writer.WriteString(result.LastQueryTime.ToString(Default.DateTimeFormatsToWrite));
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.IsStale));
            writer.WriteBool(result.IsStale);
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.ResultEtag));
            writer.WriteInteger(result.ResultEtag);

            if (partial == false)
            {
                writer.WriteEndObject();
            }
        }