Skip to content

Commit c6810ca

Browse files
Merge #609
609: Possible fix to release issue r=curquiza a=danFbach # Pull Request ## Related issue Fixes #605 ## What does this PR do? - **removes unused System.Globalization using.** this may be the fix for the issue - this is more/less a guess since i can't test the publish on my end. - while reviewing this file, i noticed that the type matching could be accomplished more easily by using built-in pattern type matching instead of reflection based type matching, also making code more readable. All tests passed. Hope this helps! ## PR checklist Please check if your PR fulfills the following requirements: - [ ] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [ ] Have you read the contributing guidelines? - [ ] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Dan Fehrenbach <[email protected]>
2 parents fd0b4d2 + a368b25 commit c6810ca

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

src/Meilisearch/Extensions/ObjectExtensions.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Globalization;
43
using System.Linq;
54
using System.Reflection;
65

@@ -43,31 +42,25 @@ internal static string ToQueryString(this object source, BindingFlags bindingAtt
4342

4443
if (value != null)
4544
{
46-
var type = value.GetType();
47-
48-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
45+
if (value is List<string> stringValue)
46+
{
47+
values.Add(key + "=" + string.Join(",", stringValue));
48+
}
49+
else if (value is List<int> intValue)
50+
{
51+
values.Add(key + "=" + string.Join(",", intValue));
52+
}
53+
else if (value is List<TaskInfoStatus> taskInfoStatusValue)
54+
{
55+
values.Add(key + "=" + string.Join(",", taskInfoStatusValue.Select(x => x.ToString())));
56+
}
57+
else if (value is List<TaskInfoType> taskInfoTypeValue)
4958
{
50-
var itemType = type.GetGenericArguments()[0];
51-
if (itemType == typeof(string))
52-
{
53-
values.Add(key + "=" + string.Join(",", (List<string>)value));
54-
}
55-
else if (itemType == typeof(int))
56-
{
57-
values.Add(key + "=" + string.Join(",", (List<int>)value));
58-
}
59-
else if (itemType == typeof(TaskInfoStatus))
60-
{
61-
values.Add(key + "=" + string.Join(",", ((List<TaskInfoStatus>)value).Select(x => x.ToString())));
62-
}
63-
else if (itemType == typeof(TaskInfoType))
64-
{
65-
values.Add(key + "=" + string.Join(",", ((List<TaskInfoType>)value).Select(x => x.ToString())));
66-
}
59+
values.Add(key + "=" + string.Join(",", taskInfoTypeValue.Select(x => x.ToString())));
6760
}
68-
else if (value is DateTime)
61+
else if (value is DateTime datetimeValue)
6962
{
70-
values.Add(key + "=" + Uri.EscapeDataString(((DateTime)value).ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz")));
63+
values.Add(key + "=" + Uri.EscapeDataString(datetimeValue.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz")));
7164
}
7265
else
7366
{

tests/Meilisearch.Tests/ObjectExtensionsTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text.Json.Serialization;
53

6-
using Meilisearch.Converters;
74
using Meilisearch.Extensions;
85
using Meilisearch.QueryParameters;
96

0 commit comments

Comments
 (0)