Implement IssuesClient and interface

This required updating our serialization strategy so we handle enums
better.
This commit is contained in:
Haacked
2013-10-22 10:29:26 -07:00
parent 1cc3da9ce3
commit ad210cecc7
35 changed files with 1278 additions and 55 deletions

View File

@@ -50,6 +50,37 @@ namespace Octokit.Internal
output = obj;
return true;
}
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase",
Justification = "The API expects lowercase values")]
protected override object SerializeEnum(Enum p)
{
return p.ToString().ToLowerInvariant();
}
// Overridden to handle enums.
public override object DeserializeObject(object value, Type type)
{
var stringValue = value as string;
if (stringValue != null)
{
if (ReflectionUtils.GetTypeInfo(type).IsEnum)
{
return Enum.Parse(type, stringValue, ignoreCase: true);
}
if (ReflectionUtils.IsNullableType(type))
{
var underlyingType = Nullable.GetUnderlyingType(type);
if (ReflectionUtils.GetTypeInfo(underlyingType).IsEnum)
{
return Enum.Parse(underlyingType, stringValue, ignoreCase: true);
}
}
}
return base.DeserializeObject(value, type);
}
}
}
}