@@ -122,7 +122,7 @@ private static void PropertyInfo(PropertyInfo property, Dictionary<string, objec
122
122
if ( p . PropertyType . GetSubTypeIfNullable ( ) . IsEnum )
123
123
{
124
124
var aliases = GetAliases ( p ) ;
125
- var row = GetEnumField ( p ) ;
125
+ var row = GetEnumField ( p , existingTypes ) ;
126
126
if ( aliases != null )
127
127
{
128
128
var rows = row . ToList ( ) ;
@@ -325,7 +325,7 @@ private static void PropertyInfo(PropertyInfo property, Dictionary<string, objec
325
325
if ( p . PropertyType . IsEnum )
326
326
{
327
327
var aliases = GetAliases ( p ) ;
328
- var row = GetEnumField ( p ) ;
328
+ var row = GetEnumField ( p , existingTypes ) ;
329
329
if ( aliases != null )
330
330
{
331
331
var rows = row . ToList ( ) ;
@@ -358,7 +358,7 @@ private static Dictionary<string, object> PropertyInfo(PropertyInfo property, Li
358
358
if ( p . PropertyType . IsEnum )
359
359
{
360
360
var aliases = GetAliases ( p ) ;
361
- var row = GetEnumField ( p ) ;
361
+ var row = GetEnumField ( p , existingTypes ) ;
362
362
if ( aliases != null )
363
363
{
364
364
var rows = row . ToList ( ) ;
@@ -549,7 +549,7 @@ private static Dictionary<string, object> PropertyInfo(PropertyInfo property, Li
549
549
if ( p . PropertyType . IsEnum )
550
550
{
551
551
var aliases = GetAliases ( p ) ;
552
- var row = GetEnumField ( p ) ;
552
+ var row = GetEnumField ( p , existingTypes ) ;
553
553
if ( aliases != null )
554
554
{
555
555
var rows = row . ToList ( ) ;
@@ -574,7 +574,7 @@ private static Dictionary<string, object> GetPropertyInfo(PropertyInfo property,
574
574
{
575
575
if ( p . PropertyType . GetSubTypeIfNullable ( ) . IsEnum )
576
576
{
577
- row = GetEnumField ( p ) ;
577
+ row = GetEnumField ( p , existingTypes ) ;
578
578
if ( aliases != null )
579
579
{
580
580
var rows = row . ToList ( ) ;
@@ -953,7 +953,7 @@ private static bool IsUserDefined(Type p)
953
953
}
954
954
955
955
private static void GetUserDefinedProperties ( PropertyInfo property , Dictionary < string , object > finalSchema ,
956
- List < string > existing )
956
+ List < string > existingTypes )
957
957
{
958
958
var schema = new Dictionary < string , object > ( ) ;
959
959
if ( ! string . IsNullOrEmpty ( property . PropertyType . Namespace ) )
@@ -970,7 +970,7 @@ private static void GetUserDefinedProperties(PropertyInfo property, Dictionary<s
970
970
{
971
971
if ( ShouldIgnore ( p ) )
972
972
continue ;
973
-
973
+
974
974
var customDefinition = CheckAndHandleCustomSchema ( p ) ;
975
975
if ( customDefinition != null )
976
976
{
@@ -983,7 +983,7 @@ private static void GetUserDefinedProperties(PropertyInfo property, Dictionary<s
983
983
var t = p . PropertyType . Name ;
984
984
var dt = p . DeclaringType ? . Name ;
985
985
var recursive = t . Equals ( dt ) ;
986
- if ( existing . Contains ( t ) )
986
+ if ( existingTypes . Contains ( t ) )
987
987
{
988
988
var pRequired = p . GetSchemaCustomAttributes ( ) . required ;
989
989
var rw = pRequired
@@ -993,26 +993,26 @@ private static void GetUserDefinedProperties(PropertyInfo property, Dictionary<s
993
993
}
994
994
else if ( recursive )
995
995
{
996
- existing . Add ( t ) ;
996
+ existingTypes . Add ( t ) ;
997
997
fieldProperties . Add ( Reuse ( p ) ) ;
998
998
}
999
999
else if ( p . PropertyType . IsEnum )
1000
1000
{
1001
1001
var pAli = GetAliases ( p ) ;
1002
1002
if ( aliases != null )
1003
1003
{
1004
- var rows = GetEnumField ( p ) . ToList ( ) ;
1004
+ var rows = GetEnumField ( p , existingTypes ) . ToList ( ) ;
1005
1005
rows . Insert ( 1 , new KeyValuePair < string , object > ( "aliases" , pAli ) ) ;
1006
1006
fieldProperties . Add ( rows . ToDictionary ( x => x . Key , x => x . Value ) ) ;
1007
1007
}
1008
- else fieldProperties . Add ( GetEnumField ( p ) ) ;
1008
+ else fieldProperties . Add ( GetEnumField ( p , existingTypes ) ) ;
1009
1009
1010
- existing . Add ( t ) ;
1010
+ existingTypes . Add ( t ) ;
1011
1011
}
1012
1012
else
1013
1013
{
1014
1014
//existing.Add(t);
1015
- var rows = PropertyInfo ( p , existing , ! existing . Contains ( t ) ) ;
1015
+ var rows = PropertyInfo ( p , existingTypes , ! existingTypes . Contains ( t ) ) ;
1016
1016
fieldProperties . Add ( rows ) ;
1017
1017
}
1018
1018
}
@@ -1026,7 +1026,7 @@ private static void GetUserDefinedProperties(PropertyInfo property, Dictionary<s
1026
1026
AddReuseType ( p , finalSchema ) ;
1027
1027
else if ( IsUserDefined ( v ) )
1028
1028
{
1029
- var schem = GetGenericUserDefinedProperties ( v , require , existing ) ;
1029
+ var schem = GetGenericUserDefinedProperties ( v , require , existingTypes ) ;
1030
1030
var row1 = require
1031
1031
? new Dictionary < string , object >
1032
1032
{
@@ -1479,8 +1479,25 @@ private static bool IsDictionary(Type t)
1479
1479
t . GetGenericTypeDefinition ( ) . IsAssignableFrom ( typeof ( Dictionary < , > ) ) ;
1480
1480
}
1481
1481
1482
- private static Dictionary < string , object > GetEnumField ( PropertyInfo p )
1482
+ private static Dictionary < string , object > GetEnumField ( PropertyInfo p , ICollection < string > existingTypes )
1483
1483
{
1484
+ var propertyTypeName = p . PropertyType . Name ;
1485
+ if ( existingTypes . Contains ( propertyTypeName ) )
1486
+ {
1487
+ List < object > lt = null ;
1488
+ if ( p . PropertyType . IsNullable ( ) )
1489
+ {
1490
+ lt = new List < object > ( ) { "null" , propertyTypeName } ;
1491
+ }
1492
+
1493
+ return new Dictionary < string , object >
1494
+ {
1495
+ { "name" , p . Name } , { "type" , lt == null ? propertyTypeName : ( object ) lt }
1496
+ } ;
1497
+ }
1498
+
1499
+ existingTypes . Add ( propertyTypeName ) ;
1500
+
1484
1501
var pt = p . PropertyType . GetSubTypeIfNullable ( ) ;
1485
1502
var dp = new Dictionary < string , object > ( ) ;
1486
1503
if ( ! string . IsNullOrEmpty ( pt . Namespace ) ) {
@@ -1581,4 +1598,4 @@ private static object ToAvroDataType(string type, LogicalTypeKind? kind)
1581
1598
}
1582
1599
}
1583
1600
}
1584
- }
1601
+ }
0 commit comments