diff --git a/lang/csharp/src/apache/main/Specific/SpecificDatumReader.cs b/lang/csharp/src/apache/main/Specific/SpecificDatumReader.cs
index 6de1b2e2b25..314a85861fe 100644
--- a/lang/csharp/src/apache/main/Specific/SpecificDatumReader.cs
+++ b/lang/csharp/src/apache/main/Specific/SpecificDatumReader.cs
@@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+using System;
using System.Collections;
using Avro.Generic;
using Avro.IO;
@@ -64,7 +65,7 @@ protected override ArrayAccess GetArrayAccess(ArraySchema readerSchema)
///
protected override EnumAccess GetEnumAccess(EnumSchema readerSchema)
{
- return new SpecificEnumAccess();
+ return new SpecificEnumAccess(readerSchema);
}
///
@@ -92,9 +93,16 @@ protected override FixedAccess GetFixedAccess(FixedSchema readerSchema)
private class SpecificEnumAccess : EnumAccess
{
+ private readonly Type enumType;
+
+ public SpecificEnumAccess(EnumSchema readerSchema)
+ {
+ enumType = ObjectCreator.Instance.GetType(readerSchema);
+ }
+
public object CreateEnum(object reuse, int ordinal)
{
- return ordinal;
+ return Enum.ToObject(enumType, ordinal);
}
}
diff --git a/lang/csharp/src/apache/test/Specific/SpecificDatumReaderEnumTests.cs b/lang/csharp/src/apache/test/Specific/SpecificDatumReaderEnumTests.cs
new file mode 100644
index 00000000000..55c65a8b091
--- /dev/null
+++ b/lang/csharp/src/apache/test/Specific/SpecificDatumReaderEnumTests.cs
@@ -0,0 +1,269 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.IO;
+using Avro.Generic;
+using Avro.IO;
+using Avro.Specific;
+using Avro.Test.AvroGen;
+using NUnit.Framework;
+
+namespace Avro.Test.Specific
+{
+ [TestFixture]
+ internal class SpecificDatumReaderEnumTests
+ {
+ private RecordSchema recordSchema;
+ private Type recordType;
+ private Type enum1Type;
+ private Type enum2Type;
+
+ [OneTimeSetUp]
+ public void GenerateSpecificTypes()
+ {
+ // Generate and load the types once so ObjectCreator resolves the same assembly in every test.
+ var assembly = AvroGenHelper.TestSchema(RecordSchemaJson);
+ recordSchema = (RecordSchema)Schema.Parse(RecordSchemaJson);
+ recordType = assembly.GetType(recordSchema.Fullname);
+ enum1Type = assembly.GetType("Avro.Test.Specific.EnumReader.Enum1");
+ enum2Type = assembly.GetType("Avro.Test.Specific.EnumReader.Enum2");
+
+ Assert.That(recordType, Is.Not.Null, "Generated record type was not found.");
+ Assert.That(enum1Type, Is.Not.Null, "Generated Enum1 type was not found.");
+ Assert.That(enum2Type, Is.Not.Null, "Generated Enum2 type was not found.");
+ }
+
+ [TestCase("FIRST")]
+ [TestCase("SECOND")]
+ [TestCase("DEFAULT")]
+ public void TestEnumProducesClrEnum(string symbol)
+ {
+ var schema = (EnumSchema)recordSchema.Fields[0].Schema;
+ var expected = Enum.Parse(enum1Type, symbol);
+ using (var stream = new MemoryStream())
+ {
+ new SpecificDatumWriter