diff --git a/src/Meilisearch/Extensions/ObjectExtensions.cs b/src/Meilisearch/Extensions/ObjectExtensions.cs index a911e2f6..1154f15a 100644 --- a/src/Meilisearch/Extensions/ObjectExtensions.cs +++ b/src/Meilisearch/Extensions/ObjectExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Reflection; @@ -43,31 +42,25 @@ internal static string ToQueryString(this object source, BindingFlags bindingAtt if (value != null) { - var type = value.GetType(); - - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) + if (value is List stringValue) + { + values.Add(key + "=" + string.Join(",", stringValue)); + } + else if (value is List intValue) + { + values.Add(key + "=" + string.Join(",", intValue)); + } + else if (value is List taskInfoStatusValue) + { + values.Add(key + "=" + string.Join(",", taskInfoStatusValue.Select(x => x.ToString()))); + } + else if (value is List taskInfoTypeValue) { - var itemType = type.GetGenericArguments()[0]; - if (itemType == typeof(string)) - { - values.Add(key + "=" + string.Join(",", (List)value)); - } - else if (itemType == typeof(int)) - { - values.Add(key + "=" + string.Join(",", (List)value)); - } - else if (itemType == typeof(TaskInfoStatus)) - { - values.Add(key + "=" + string.Join(",", ((List)value).Select(x => x.ToString()))); - } - else if (itemType == typeof(TaskInfoType)) - { - values.Add(key + "=" + string.Join(",", ((List)value).Select(x => x.ToString()))); - } + values.Add(key + "=" + string.Join(",", taskInfoTypeValue.Select(x => x.ToString()))); } - else if (value is DateTime) + else if (value is DateTime datetimeValue) { - values.Add(key + "=" + Uri.EscapeDataString(((DateTime)value).ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz"))); + values.Add(key + "=" + Uri.EscapeDataString(datetimeValue.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz"))); } else { diff --git a/tests/Meilisearch.Tests/ObjectExtensionsTests.cs b/tests/Meilisearch.Tests/ObjectExtensionsTests.cs index 53894c14..ed4e04d0 100644 --- a/tests/Meilisearch.Tests/ObjectExtensionsTests.cs +++ b/tests/Meilisearch.Tests/ObjectExtensionsTests.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text.Json.Serialization; -using Meilisearch.Converters; using Meilisearch.Extensions; using Meilisearch.QueryParameters;