Copilot commented on code in PR #3388:
URL: https://github.com/apache/avro/pull/3388#discussion_r2454655348


##########
lang/csharp/src/apache/main/Specific/SpecificWriter.cs:
##########
@@ -209,7 +209,7 @@ protected override bool Matches(Schema sc, object obj)
                     return obj is ISpecificRecord &&
                            ((obj as ISpecificRecord).Schema as 
RecordSchema).SchemaName.Equals((sc as RecordSchema).SchemaName);
                 case Schema.Type.Enumeration:
-                    return obj.GetType().IsEnum && (sc as 
EnumSchema).Symbols.Contains(obj.ToString());
+                    return obj.GetType().IsEnum && (sc as 
EnumSchema).Symbols.Contains(obj.ToString()) && 
sc.Name.Equals(obj.GetType().Name);

Review Comment:
   The name comparison may fail for enums in namespaced schemas. The schema's 
`Name` property typically contains only the simple name, while 
`obj.GetType().Name` returns the C# type name. Consider using 
`SchemaName.Equals()` or `Fullname` for more robust matching, similar to how 
the Record case on line 210 uses `SchemaName.Equals()`.
   ```suggestion
                       return obj.GetType().IsEnum && (sc as 
EnumSchema).Symbols.Contains(obj.ToString()) &&
                              ((sc as 
EnumSchema).SchemaName.Equals(obj.GetType().FullName));
   ```



##########
lang/csharp/src/apache/main/Specific/SpecificDatumWriter.cs:
##########
@@ -139,7 +139,7 @@ protected override bool UnionBranchMatches( Schema sc, 
object obj )
                     return obj is ISpecificRecord &&
                            ((obj as ISpecificRecord).Schema as 
RecordSchema).SchemaName.Equals((sc as RecordSchema).SchemaName);
                 case Schema.Type.Enumeration:
-                    return obj.GetType().IsEnum && (sc as 
EnumSchema).Symbols.Contains(obj.ToString());
+                    return obj.GetType().IsEnum && (sc as 
EnumSchema).Symbols.Contains(obj.ToString()) && 
sc.Name.Equals(obj.GetType().Name);

Review Comment:
   The name comparison may fail for enums in namespaced schemas. The schema's 
`Name` property typically contains only the simple name, while 
`obj.GetType().Name` returns the C# type name. Consider using 
`SchemaName.Equals()` or `Fullname` for more robust matching, similar to how 
the Record case on line 140 uses `SchemaName.Equals()`.
   ```suggestion
                       return obj.GetType().IsEnum
                           && (sc as 
EnumSchema).Symbols.Contains(obj.ToString())
                           && (sc as 
EnumSchema).SchemaName.Equals(obj.GetType());
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to