/// <summary> /// Works simmilar to ExecuteNextAsyc<T> from IDocumentQuery<T> and allows to deserialize the results /// to custom objects of type T /// </summary> /// <typeparam name="T"></typeparam> /// <param name="gremlinQuery">ExtensionObject IDocumentQuery</param> /// <param name="context">Context that can store GraphElements. If you retrieved vertices and then an edge refering to those vertices they will be automatically linked.</param> /// <returns></returns> public static async Task <IList <T> > ExecuteNextAsyncAsPOCO <T>(this IDocumentQuery gremlinQuery, IGraphContext context = null) // where T : new() { List <T> result = new List <T>(); IGraphSerializer serializer = null; Type targetType = typeof(T); if (gremlinQuery.GetType().GenericTypeArguments[0] != typeof(Vertex)) { IDocumentQuery <Edge> edgeQuery = gremlinQuery as IDocumentQuery <Edge>; var resultSet = await edgeQuery.ExecuteNextAsync <Edge>(); foreach (Edge e in resultSet) { string typeString = GraphSerializer.GetTypePropertyString(e, out string inVTypeString, out string outVTypeString); if (String.IsNullOrEmpty(typeString)) { serializer = GraphSerializerFactory.CreateGraphSerializer(context, targetType); // Try to instantiate T } else { serializer = GraphSerializerFactory.CreateGraphSerializer(context, typeString); } serializer.Convert(e, out object edge); result.Add((T)edge); } } else { IDocumentQuery <Vertex> vertexQuery = gremlinQuery as IDocumentQuery <Vertex>; var resultSet = await vertexQuery.ExecuteNextAsync <Vertex>(); foreach (Vertex v in resultSet) { string typeString = GraphSerializer.GetTypePropertyString(v); if (String.IsNullOrEmpty(typeString)) { serializer = GraphSerializerFactory.CreateGraphSerializer(context, targetType); // Try to instantiate T } else { serializer = GraphSerializerFactory.CreateGraphSerializer(context, typeString); } serializer.Convert(v, out object vertex); result.Add((T)vertex); } } return(result); }