Skip to content

Commit

Permalink
Merge #609
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meili-bors[bot] and danFbach authored Jan 15, 2025
2 parents fd0b4d2 + a368b25 commit c6810ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
39 changes: 16 additions & 23 deletions src/Meilisearch/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -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<string> stringValue)
{
values.Add(key + "=" + string.Join(",", stringValue));
}
else if (value is List<int> intValue)
{
values.Add(key + "=" + string.Join(",", intValue));
}
else if (value is List<TaskInfoStatus> taskInfoStatusValue)
{
values.Add(key + "=" + string.Join(",", taskInfoStatusValue.Select(x => x.ToString())));
}
else if (value is List<TaskInfoType> taskInfoTypeValue)
{
var itemType = type.GetGenericArguments()[0];
if (itemType == typeof(string))
{
values.Add(key + "=" + string.Join(",", (List<string>)value));
}
else if (itemType == typeof(int))
{
values.Add(key + "=" + string.Join(",", (List<int>)value));
}
else if (itemType == typeof(TaskInfoStatus))
{
values.Add(key + "=" + string.Join(",", ((List<TaskInfoStatus>)value).Select(x => x.ToString())));
}
else if (itemType == typeof(TaskInfoType))
{
values.Add(key + "=" + string.Join(",", ((List<TaskInfoType>)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
{
Expand Down
3 changes: 0 additions & 3 deletions tests/Meilisearch.Tests/ObjectExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit c6810ca

Please sign in to comment.