@@ -111,10 +111,12 @@ private static EntryValue CreateEntryValue(PropertyInfo property, ICustomSeriali
111111 isReadOnly = readOnlyAtt ? . IsReadOnly ?? false ;
112112 }
113113
114+ var type = TransformType ( property . PropertyType ) ;
115+
114116 // Prepare object
115117 var entryValue = new EntryValue
116118 {
117- Type = TransformType ( property . PropertyType ) ,
119+ Type = type ,
118120 UnitType = customSerialization . GetUnitTypeByAttributes ( property ) ,
119121 IsReadOnly = isReadOnly ,
120122 Possible = customSerialization . PossibleValues ( property . PropertyType , property )
@@ -126,10 +128,14 @@ private static EntryValue CreateEntryValue(PropertyInfo property, ICustomSeriali
126128 entryValue . Default = defaultAttribute . Value . ToString ( ) ;
127129 else if ( entryValue . Possible != null && entryValue . Possible . Length >= 1 )
128130 entryValue . Default = entryValue . Possible [ 0 ] ;
129- else if ( property . PropertyType . IsValueType )
130- entryValue . Default = Activator . CreateInstance ( property . PropertyType ) . ToString ( ) ;
131-
132- // Value types should have the default value as current value
131+ else if ( property . PropertyType . IsValueType )
132+ {
133+ var underlyingType = Nullable . GetUnderlyingType ( property . PropertyType ) ;
134+ entryValue . Default = underlyingType != null
135+ ? Activator . CreateInstance ( underlyingType ) . ToString ( )
136+ : Activator . CreateInstance ( property . PropertyType ) . ToString ( ) ;
137+ }
138+ // Value types should have the default value as current value
133139 if ( ValueOrStringType ( property . PropertyType ) )
134140 entryValue . Current = ConvertToString ( entryValue . Default , customSerialization . FormatProvider ) ;
135141
@@ -313,7 +319,10 @@ public static Entry EncodeObject(object instance, ICustomSerialization customSer
313319 convertedProperty . SubEntries = subEntry . SubEntries ;
314320 break ;
315321 case EntryValueType . Exception :
316- convertedProperty . Value . Current = ExceptionPrinter . Print ( ( Exception ) value ) ;
322+ //if (value is Exception exceptionValue)
323+ //{
324+ convertedProperty . Value . Current = ExceptionPrinter . Print ( ( Exception ) value ) ;
325+ //}
317326 break ;
318327 case EntryValueType . Stream :
319328 var stream = value as Stream ;
0 commit comments