File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
Dahomey.Cbor.Tests/Issues
Dahomey.Cbor/Serialization/Converters Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,12 @@ public class ObjectWithNullLists
1515 public List < string > Items { get ; set ; }
1616 }
1717
18- [ Fact ]
18+ public class ObjectWithNullDictionary
19+ {
20+ public Dictionary < string , string > Items { get ; set ; }
21+ }
22+
23+ [ Fact ]
1924 public void TestNullReferenceList ( )
2025 {
2126
@@ -33,7 +38,7 @@ public void TestNullReferenceList()
3338
3439 }
3540
36- [ Fact ]
41+ [ Fact ]
3742 public void TestNullReferenceArray ( )
3843 {
3944
@@ -50,5 +55,22 @@ public void TestNullReferenceArray()
5055 Assert . Equal ( "A1654279746573F6" , hexResult ) ;
5156 }
5257
53- }
58+
59+ [ Fact ]
60+ public void TestNullReferenceDictionary ( )
61+ {
62+ var obj = new ObjectWithNullDictionary ( ) ;
63+
64+ string hexResult = null ;
65+
66+ var ex = Record . Exception ( ( ) => {
67+ hexResult = Helper . Write ( obj ) ;
68+ } ) ;
69+
70+ Assert . NotEmpty ( hexResult ) ;
71+ Assert . Null ( ex ) ;
72+ Assert . Equal ( "A1654974656D73F6" , hexResult ) ;
73+
74+ }
75+ }
5476}
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ public override TC Read(ref CborReader reader)
4545
4646 public override void Write ( ref CborWriter writer , TC value )
4747 {
48+ if ( value == null )
49+ {
50+ writer . WriteNull ( ) ;
51+ return ;
52+ }
4853 WriterContext context = new WriterContext
4954 {
5055 count = value . Count ,
You can’t perform that action at this time.
0 commit comments