Skip to content

Commit f491c74

Browse files
committed
remove unused System.Globalization using.
use pattern type matching instead of reflection based type matching, making code more readable.
1 parent b914e19 commit f491c74

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
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
{

0 commit comments

Comments
 (0)