From b3ceb1d661cf78d3c3603136f9aac5b29e30666c Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Mon, 4 Nov 2013 17:26:56 +1100 Subject: [PATCH] we should deserialize Urls in a specific way --- Octokit/Http/SimpleJsonSerializer.cs | 9 +++++++++ Octokit/SimpleJson.cs | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index c32c5544..80f9464a 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -64,6 +64,15 @@ namespace Octokit.Internal var stringValue = value as string; if (stringValue != null) { + if (ReflectionUtils.IsUri(type)) + { + Uri result; + if (Uri.TryCreate(stringValue, UriKind.RelativeOrAbsolute, out result)) + { + return result; + } + } + if (ReflectionUtils.GetTypeInfo(type).IsEnum) { return Enum.Parse(type, stringValue, ignoreCase: true); diff --git a/Octokit/SimpleJson.cs b/Octokit/SimpleJson.cs index 613894b7..fdb57d48 100644 --- a/Octokit/SimpleJson.cs +++ b/Octokit/SimpleJson.cs @@ -1667,6 +1667,11 @@ namespace Octokit return GetTypeInfo(type).IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); } + public static bool IsUri(Type type) + { + return GetTypeInfo(type) == GetTypeInfo(typeof(Uri)); + } + public static object ToNullableType(object obj, Type nullableType) { return obj == null ? null : Convert.ChangeType(obj, Nullable.GetUnderlyingType(nullableType), CultureInfo.InvariantCulture);