mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Deserializer should handle nullable StringEnum<T> (#1760)
* add deserializer tests for nullable enums, StringEnum and nullable StringEnum properties * Fix deserializing nullable structs by using the underlying type when nullable * StringEnum<T> should behave like an enum, returning default(T) when it is uninitialised/null/blank * Don't allow null to be passed into StringEnum ctor - if it needs to be null then it should be declared as nullable * fix expected json * move logic to determine if property is a StringEnum<T> into helper function * serializer needs to treat StringEnum<T> specially by serializing the enum value according to existing serializer strategy (parameter attributes and so on) * remove fallback to default(T) * add test to assert ctor throws exception when null passed in * remove test for default(T) fallback behaviour * Fix exception in serializer test - StringEnum property must be initialized otherwise an exception is thrown when attempting to serialize * Dont allow empty strings either
This commit is contained in:
@@ -29,7 +29,9 @@ namespace Octokit
|
||||
|
||||
public StringEnum(string stringValue)
|
||||
{
|
||||
_stringValue = stringValue ?? string.Empty;
|
||||
Ensure.ArgumentNotNullOrEmptyString(stringValue, nameof(stringValue));
|
||||
|
||||
_stringValue = stringValue;
|
||||
_parsedValue = null;
|
||||
}
|
||||
|
||||
@@ -66,12 +68,6 @@ namespace Octokit
|
||||
return true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(StringValue))
|
||||
{
|
||||
value = default(TEnum);
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Use the SimpleJsonSerializer to parse the string to Enum according to the GitHub Api strategy
|
||||
|
||||
Reference in New Issue
Block a user