ArangoDB-Community / arangodb-net-standard

A consistent, comprehensive, minimal interface to enable .NET applications to use the complete range of features exposed by the ArangoDB REST API.
Apache License 2.0
76 stars 29 forks source link

Support FrozenSet<T> in PostDocumentsAsync<T>(...), PutDocumentsAsync<T>(...) and PatchDocumentsAsync<T>(...) #484

Closed Arash-Sabet closed 9 months ago

Arash-Sabet commented 9 months ago

FrozenSet<T> is now shipped with .NET 8.0 and we started leveraging it. We have to convert our frozen sets to List<T> using .ToList() extension method when calling any of the methods in the title. It makes sense to introduce three more overloads of the aforementioned methods to support frozen sets in ArangoDB's .NET client library.

rossmills99 commented 9 months ago

Signature of e.g. PostDocumentsAsync:

public virtual async Task<PostDocumentsResponse<T>> PostDocumentsAsync<T>(
            string collectionName,
            IList<T> documents,
            PostDocumentsQuery query = null,
            ApiClientSerializationOptions serializationOptions = null,
            DocumentHeaderProperties headers = null,
            CancellationToken token = default)

I assume you are referring to IList<T> documents. I'm not sure why the decision was made to use IList<T> there, but looking at documentation, I think that both FrozenSet<T> and IList<T> implement IEnumerable<T>. So perhaps the best way to fix this is to change IList to IEnumerable in the method signatures?

Arash-Sabet commented 9 months ago

@rossmills99 That might help, or preferably a separate extension method to intake the FrozenSet<T> would be a better way. As a side note, typecasting to IList<T> throws an exception and therefore .ToList() had to be used.

rossmills99 commented 9 months ago

Thanks. Yes, I think using the more general IEnumerable<T> type here will be the best option - it then allows for any collection type that supports that interface, which includes FrozenSet<T>, or anything that implements IList<T>. This is better than creating overloads specific to any particular collection type. I can push up a quick PR.

Arash-Sabet commented 9 months ago

@rossmills99 That's amazing. thanks for the prompt action.