You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/07/06 11:02:22 UTC

[GitHub] [avro] RobertIndie commented on a diff in pull request #1348: AVRO-3219: Add nullable enum type field support.

RobertIndie commented on code in PR #1348:
URL: https://github.com/apache/avro/pull/1348#discussion_r914708235


##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -254,15 +254,31 @@ public void LoadClassCache(Type objType, Schema s)
                     EnumCache.AddEnumNameMapItem(ns, objType);
                     break;
                 case UnionSchema us:
-                    if (us.Schemas.Count == 2 && (us.Schemas[0].Tag == Schema.Type.Null || us.Schemas[1].Tag == Schema.Type.Null) && objType.IsClass)
+                    if (us.Schemas.Count == 2 && (us.Schemas[0].Tag == Schema.Type.Null || us.Schemas[1].Tag == Schema.Type.Null))
                     {
                         // in this case objType will match the non null type in the union
                         foreach (var o in us.Schemas)
                         {
-                            if (o.Tag != Schema.Type.Null)
+                            if (o.Tag == Schema.Type.Null)
+                            {
+                                continue;
+                            }
+
+                            if (objType.IsClass)
                             {
                                 LoadClassCache(objType, o);
                             }
+
+                            if (objType.IsGenericType)
+                            {
+                                var genericType = objType.GetGenericTypeDefinition();
+                                var isNullable = genericType == typeof(Nullable<>);
+                                var innerType = objType.GetGenericArguments()[0];
+                                if (isNullable && innerType.IsEnum)
+                                {
+                                    LoadClassCache(objType.GetGenericArguments()[0], o);
+                                }
+                            }

Review Comment:
   Thanks! This makes the code much more simple.



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org