You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by bl...@apache.org on 2019/10/06 11:33:19 UTC

[avro] 01/02: AVRO-2522: Handle record types with Nullable and IList in their names (#663)

This is an automated email from the ASF dual-hosted git repository.

blachniet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 85ce0227e427e5f7b5c84cfe59293e1b649b925a
Author: Brian Lachniet <bl...@gmail.com>
AuthorDate: Sat Aug 24 08:36:49 2019 -0400

    AVRO-2522: Handle record types with Nullable and IList in their names
    (#663)
---
 .../src/apache/main/Specific/ObjectCreator.cs      |  5 ++---
 .../src/apache/test/Specific/ObjectCreatorTests.cs | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs b/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
index 00a7f36..b0cf9ef 100644
--- a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
+++ b/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
@@ -138,9 +138,8 @@ namespace Avro.Specific
 
                 // Modify provided type to ensure it can be discovered.
                 // This is mainly for Generics, and Nullables.
-                name = name.Replace("Nullable", "Nullable`1");
-                name = name.Replace("IList", "System.Collections.Generic.IList`1");
-                name = name.Replace("<", "[");
+                name = name.Replace("Nullable<", "Nullable`1[");
+                name = name.Replace("IList<", "System.Collections.Generic.IList`1[");
                 name = name.Replace(">", "]");
 
                 // if entry assembly different from current assembly, try entry assembly first
diff --git a/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs b/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs
index e95c10a..f17ff55 100644
--- a/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs
+++ b/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs
@@ -18,9 +18,10 @@
 using Avro.Specific;
 using Avro.Test.File;
 using NUnit.Framework;
+using System;
 using System.Collections.Generic;
 
-namespace Avro.test.Specific
+namespace Avro.Test.Specific
 {
     [TestFixture()]
     public class ObjectCreatorTests
@@ -78,5 +79,24 @@ namespace Avro.test.Specific
             Assert.True(typeof(IDictionary<string, Foo>).IsAssignableFrom(
                 objectCreator.GetType("Foo", Schema.Type.Map)));
         }
+
+        [TestCase(typeof(MyNullableFoo), "MyNullableFoo",
+            TestName = "TestComplexGetTypes_NullableInName")]
+        [TestCase(typeof(MyIListFoo), "MyIListFoo",
+            TestName = "TestComplexGetTypes_IListInName")]
+        public void TestComplexGetTypes(Type expecteType, string name)
+        {
+            var objectCreator = new ObjectCreator();
+
+            Assert.AreEqual(expecteType, objectCreator.GetType(name, Schema.Type.Record));
+        }
+
+        private class MyNullableFoo
+        {
+        }
+
+        private class MyIListFoo
+        {
+        }
     }
 }