we should deserialize Urls in a specific way

This commit is contained in:
Brendan Forster
2013-11-04 17:26:56 +11:00
parent eb7c198a67
commit b3ceb1d661
2 changed files with 14 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);