Merge pull request #727 from janovesk/master

Support the correct spelling of event types, take two.
This commit is contained in:
Phil Haack
2015-02-25 21:06:35 -08:00
3 changed files with 20 additions and 3 deletions
@@ -80,8 +80,16 @@ namespace Octokit.Tests
}
}
public class TheDeserializeMethod
{
[Fact]
public void DeserializesEventInfosWithUnderscoresInName()
{
const string json = "{\"event\":\"head_ref_deleted\"}";
new SimpleJsonSerializer().Deserialize<EventInfo>(json);
}
[Fact]
public void UnderstandsRubyCasing()
{
+12 -1
View File
@@ -87,10 +87,11 @@ namespace Octokit.Internal
var stringValue = value as string;
if (stringValue != null)
{
stringValue = stringValue.Replace("-", "");
if (ReflectionUtils.GetTypeInfo(type).IsEnum)
{
// remove '-' from values coming in to be able to enum utf-8
stringValue = stringValue.Replace("-", "");
stringValue = RemoveHyphenAndUnderscore(stringValue);
return Enum.Parse(type, stringValue, ignoreCase: true);
}
@@ -99,6 +100,7 @@ namespace Octokit.Internal
var underlyingType = Nullable.GetUnderlyingType(type);
if (ReflectionUtils.GetTypeInfo(underlyingType).IsEnum)
{
stringValue = RemoveHyphenAndUnderscore(stringValue);
return Enum.Parse(underlyingType, stringValue, ignoreCase: true);
}
}
@@ -118,6 +120,15 @@ namespace Octokit.Internal
return base.DeserializeObject(value, type);
}
static string RemoveHyphenAndUnderscore(string stringValue)
{
// remove '-' from values coming in to be able to enum utf-8
stringValue = stringValue.Replace("-", "");
// remove '-' from values coming in to be able to enum EventInfoState names with underscores in them. Like "head_ref_deleted"
stringValue = stringValue.Replace("_", "");
return stringValue;
}
internal override IDictionary<string, KeyValuePair<Type, ReflectionUtils.SetDelegate>> SetterValueFactory(Type type)
{
return type.GetPropertiesAndFields()
-2
View File
@@ -156,13 +156,11 @@ namespace Octokit
/// <summary>
/// The pull requests branch was deleted.
/// </summary>
[Parameter(Value = "head_ref_deleted")]
HeadRefDeleted,
/// <summary>
/// The pull requests branch was restored.
/// </summary>
[Parameter(Value = "head_ref_restored")]
HeadRefRestored,
}
}