@@ -80,7 +80,7 @@ public static bool IsNumericType(Type type, bool isNullableUnderlyingType = fals
80
80
}
81
81
else if ( pInfo . ExcludeNullableType == typeof ( Guid ) )
82
82
{
83
- newValue = Guid . Parse ( itemValue . ToString ( ) ) ;
83
+ newValue = Guid . Parse ( itemValue . ToString ( ) ?? Guid . Empty . ToString ( ) ) ;
84
84
}
85
85
else if ( pInfo . ExcludeNullableType == typeof ( DateTimeOffset ) )
86
86
{
@@ -100,7 +100,7 @@ public static bool IsNumericType(Type type, bool isNullableUnderlyingType = fals
100
100
else if ( pInfo . ExcludeNullableType == typeof ( DateTime ) )
101
101
{
102
102
// fix issue 257 https://github.com/shps951023/MiniExcel/issues/257
103
- if ( itemValue is DateTime || itemValue is DateTime ? )
103
+ if ( itemValue is DateTime )
104
104
{
105
105
newValue = itemValue ;
106
106
pInfo . Property . SetValue ( v , newValue ) ;
@@ -128,9 +128,37 @@ public static bool IsNumericType(Type type, bool isNullableUnderlyingType = fals
128
128
else
129
129
throw new InvalidCastException ( $ "{ vs } cannot be cast to DateTime") ;
130
130
}
131
+ #if NET6_0_OR_GREATER
132
+ else if ( pInfo . ExcludeNullableType = = typeof ( DateOnly ) )
133
+ {
134
+ if ( itemValue is DateOnly )
135
+ {
136
+ newValue = itemValue ;
137
+ pInfo . Property . SetValue ( v , newValue ) ;
138
+ return newValue ;
139
+ }
140
+
141
+ var vs = itemValue ? . ToString ( ) ;
142
+ if ( pInfo . ExcelFormat != null )
143
+ {
144
+ if ( DateOnly . TryParseExact ( vs , pInfo . ExcelFormat , CultureInfo . InvariantCulture , DateTimeStyles . None , out var _v ) )
145
+ {
146
+ newValue = _v ;
147
+ }
148
+ }
149
+ else if ( DateOnly . TryParse ( vs , _config . Culture , DateTimeStyles . None , out var _v ) )
150
+ newValue = _v ;
151
+ else if ( DateOnly . TryParseExact ( vs , "dd/MM/yyyy" , CultureInfo . InvariantCulture , DateTimeStyles . None , out var _v2 ) )
152
+ newValue = _v2 ;
153
+ else if ( double . TryParse ( vs , NumberStyles . None , CultureInfo . InvariantCulture , out var _d ) )
154
+ newValue = DateOnly . FromDateTime ( DateTime . FromOADate ( _d ) ) ;
155
+ else
156
+ throw new InvalidCastException ( $ "{ vs } cannot be cast to DateOnly") ;
157
+ }
158
+ #endif
131
159
else if ( pInfo . ExcludeNullableType = = typeof ( TimeSpan ) )
132
160
{
133
- if ( itemValue is TimeSpan || itemValue is TimeSpan ? )
161
+ if ( itemValue is TimeSpan )
134
162
{
135
163
newValue = itemValue ;
136
164
pInfo . Property . SetValue ( v , newValue ) ;
0 commit comments