Skip to content

Commit 87c81d1

Browse files
committed
Enum and Boolean deserization should be same for all deserializers
1 parent ea73617 commit 87c81d1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

RestSharp/Deserializers/XmlAttributeDeserializer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Collections.Generic;
2020
using System.Globalization;
2121
using System.Linq;
22+
using System.Xml;
2223
using System.Xml.Linq;
2324
using RestSharp.Extensions;
2425

@@ -140,13 +141,18 @@ private void Map(object x, XElement root)
140141
}
141142
}
142143

143-
if (type.IsPrimitive)
144+
if (type == typeof(bool))
145+
{
146+
var toConvert = value.ToString().ToLower();
147+
prop.SetValue(x, XmlConvert.ToBoolean(toConvert), null);
148+
}
149+
else if (type.IsPrimitive)
144150
{
145151
prop.SetValue(x, value.ChangeType(type, Culture), null);
146152
}
147153
else if (type.IsEnum)
148154
{
149-
var converted = Enum.Parse(type, value.ToString(), false);
155+
var converted = type.FindEnumValue(value.ToString(), Culture);
150156
prop.SetValue(x, converted, null);
151157
}
152158
else if (type == typeof(Uri))

RestSharp/Extensions/ReflectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static object FindEnumValue(this Type type, string value, CultureInfo cul
9494
#if FRAMEWORK
9595
return Enum.GetValues(type)
9696
.Cast<Enum>()
97-
.First(v => v.ToString().GetNameVariants(culture).Contains(value));
97+
.First(v => v.ToString().GetNameVariants(culture).Contains(value, StringComparer.Create(culture, true)));
9898
#else
9999
return Enum.Parse(type, value, true);
100100
#endif

0 commit comments

Comments
 (0)