blachniet commented on a change in pull request #820:
URL: https://github.com/apache/avro/pull/820#discussion_r383003202
##########
File path: lang/csharp/src/apache/main/Generic/GenericEnum.cs
##########
@@ -37,8 +37,15 @@ public class GenericEnum
get { return value; }
set
{
- if (! Schema.Contains(value)) throw new AvroException("Unknown
value for enum: " + value + "(" + Schema + ")");
- this.value = value;
+ if (!string.IsNullOrEmpty(Schema.Default))
+ {
+ this.value = Schema.Contains(value) ? value :
Schema.Default;
+ }
+ else
+ {
+ if (! Schema.Contains(value)) throw new
AvroException("Unknown value for enum: " + value + "(" + Schema + ")");
+ this.value = value;
+ }
Review comment:
We could change up the order of these checks to simplify the code a
little. We would only have to check whether or not `Schema.Default` is
null/empty when the schema doesn't contain the given value, which is something
we always have to check.
```c#
if (!Schema.Contains(value))
{
if (!string.IsNullOrEmpty(Schema.Default))
{
this.value = Schema.Default;
}
else
{
throw new AvroException("Unknown value for enum: " + value + "(" +
Schema + ")");
}
}
else
{
this.value = value;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]