40
40
#endif // !WATCH
41
41
#endif
42
42
43
+ #nullable enable
44
+
43
45
namespace Foundation {
44
46
45
47
public abstract class DictionaryContainer
@@ -50,16 +52,14 @@ protected DictionaryContainer ()
50
52
Dictionary = new NSMutableDictionary ( ) ;
51
53
}
52
54
53
- protected DictionaryContainer ( NSDictionary dictionary )
55
+ protected DictionaryContainer ( NSDictionary ? dictionary )
54
56
{
55
- if ( dictionary == null )
56
- throw new ArgumentNullException ( "dictionary" ) ;
57
- Dictionary = dictionary ;
57
+ Dictionary = dictionary ?? new NSMutableDictionary ( ) ;
58
58
}
59
59
60
60
public NSDictionary Dictionary { get ; private set ; }
61
61
62
- protected T [ ] GetArray < T > ( NSString key ) where T : NSObject
62
+ protected T [ ] ? GetArray < T > ( NSString key ) where T : NSObject
63
63
{
64
64
if ( key == null )
65
65
throw new ArgumentNullException ( "key" ) ;
@@ -71,7 +71,7 @@ protected T[] GetArray<T> (NSString key) where T : NSObject
71
71
return NSArray . ArrayFromHandle < T > ( value ) ;
72
72
}
73
73
74
- protected T [ ] GetArray < T > ( NSString key , Func < IntPtr , T > creator )
74
+ protected T [ ] ? GetArray < T > ( NSString key , Func < IntPtr , T > creator )
75
75
{
76
76
if ( key == null )
77
77
throw new ArgumentNullException ( "key" ) ;
@@ -199,15 +199,15 @@ protected T[] GetArray<T> (NSString key, Func<IntPtr, T> creator)
199
199
return CFBoolean . GetValue ( value ) ;
200
200
}
201
201
202
- protected T GetNativeValue < T > ( NSString key ) where T : class , INativeObject
202
+ protected T ? GetNativeValue < T > ( NSString key ) where T : class , INativeObject
203
203
{
204
204
if ( key == null )
205
205
throw new ArgumentNullException ( "key" ) ;
206
206
207
207
return Runtime . GetINativeObject < T > ( Dictionary . LowlevelObjectForKey ( key . Handle ) , false ) ;
208
208
}
209
209
210
- protected NSDictionary GetNSDictionary ( NSString key )
210
+ protected NSDictionary ? GetNSDictionary ( NSString key )
211
211
{
212
212
if ( key == null )
213
213
throw new ArgumentNullException ( "key" ) ;
@@ -218,7 +218,7 @@ protected NSDictionary GetNSDictionary (NSString key)
218
218
}
219
219
220
220
#if XAMCORE_2_0
221
- protected NSDictionary < TKey , TValue > GetNSDictionary < TKey , TValue > ( NSString key )
221
+ protected NSDictionary < TKey , TValue > ? GetNSDictionary < TKey , TValue > ( NSString key )
222
222
where TKey : class , INativeObject
223
223
where TValue : class , INativeObject
224
224
{
@@ -231,22 +231,20 @@ protected NSDictionary GetNSDictionary (NSString key)
231
231
}
232
232
#endif
233
233
234
- protected T GetStrongDictionary < T > ( NSString key ) where T : DictionaryContainer
234
+ protected T ? GetStrongDictionary < T > ( NSString key ) where T : DictionaryContainer
235
235
{
236
236
if ( key == null )
237
237
throw new ArgumentNullException ( "key" ) ;
238
238
239
239
var dict = GetNSDictionary ( key ) ;
240
240
if ( dict == null )
241
241
return null ;
242
- T value = ( T ) Activator . CreateInstance ( typeof ( T ) ,
242
+ return ( T ? ) Activator . CreateInstance ( typeof ( T ) ,
243
243
new object [ ] { dict }
244
244
) ;
245
-
246
- return value ;
247
245
}
248
246
249
- protected NSString GetNSStringValue ( NSString key )
247
+ protected NSString ? GetNSStringValue ( NSString key )
250
248
{
251
249
if ( key == null )
252
250
throw new ArgumentNullException ( "key" ) ;
@@ -256,7 +254,7 @@ protected NSString GetNSStringValue (NSString key)
256
254
return value as NSString ;
257
255
}
258
256
259
- protected string GetStringValue ( NSString key )
257
+ protected string ? GetStringValue ( NSString key )
260
258
{
261
259
if ( key == null )
262
260
throw new ArgumentNullException ( "key" ) ;
@@ -268,7 +266,7 @@ protected string GetStringValue (NSString key)
268
266
return CFString . FetchString ( value . Handle ) ;
269
267
}
270
268
271
- protected string GetStringValue ( string key )
269
+ protected string ? GetStringValue ( string key )
272
270
{
273
271
if ( key == null )
274
272
throw new ArgumentNullException ( "key" ) ;
@@ -330,36 +328,36 @@ bool NullCheckAndRemoveKey (NSString key, bool removeEntry)
330
328
return ! removeEntry ;
331
329
}
332
330
333
- protected void SetArrayValue ( NSString key , NSNumber [ ] values )
331
+ protected void SetArrayValue ( NSString key , NSNumber [ ] ? values )
334
332
{
335
333
if ( NullCheckAndRemoveKey ( key , values == null ) )
336
334
Dictionary [ key ] = NSArray . FromNSObjects ( values ) ;
337
335
}
338
336
339
- protected void SetArrayValue < T > ( NSString key , T [ ] values )
337
+ protected void SetArrayValue < T > ( NSString key , T [ ] ? values )
340
338
{
341
339
if ( NullCheckAndRemoveKey ( key , values == null ) )
342
340
Dictionary [ key ] = NSArray . FromNSObjects ( values . Select ( x => NSObject . FromObject ( x ) ) . ToArray ( ) ) ;
343
341
}
344
342
345
- protected void SetArrayValue ( NSString key , string [ ] values )
343
+ protected void SetArrayValue ( NSString key , string [ ] ? values )
346
344
{
347
345
if ( NullCheckAndRemoveKey ( key , values == null ) )
348
- Dictionary [ key ] = NSArray . FromStrings ( values ) ;
346
+ Dictionary [ key ! ] = NSArray . FromStrings ( values ) ;
349
347
}
350
348
351
- protected void SetArrayValue ( NSString key , INativeObject [ ] values )
349
+ protected void SetArrayValue ( NSString key , INativeObject [ ] ? values )
352
350
{
353
351
if ( NullCheckAndRemoveKey ( key , values == null ) )
354
- CFMutableDictionary . SetValue ( Dictionary . Handle , key . Handle , CFArray . FromNativeObjects ( values ) . Handle ) ;
352
+ CFMutableDictionary . SetValue ( Dictionary . Handle , key ! . Handle , CFArray . FromNativeObjects ( values ) . Handle ) ;
355
353
}
356
354
357
355
#region Sets CFBoolean value
358
356
359
357
protected void SetBooleanValue ( NSString key , bool ? value )
360
358
{
361
359
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
362
- CFMutableDictionary . SetValue ( Dictionary . Handle , key . Handle , value . Value ? CFBoolean . TrueHandle : CFBoolean . FalseHandle ) ;
360
+ CFMutableDictionary . SetValue ( Dictionary . Handle , key ! . Handle , value ! . Value ? CFBoolean . TrueHandle : CFBoolean . FalseHandle ) ;
363
361
}
364
362
365
363
#endregion
@@ -369,67 +367,67 @@ protected void SetBooleanValue (NSString key, bool? value)
369
367
protected void SetNumberValue ( NSString key , int ? value )
370
368
{
371
369
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
372
- Dictionary [ key ] = new NSNumber ( value . Value ) ;
370
+ Dictionary [ key ! ] = new NSNumber ( value ! . Value ) ;
373
371
}
374
372
375
373
protected void SetNumberValue ( NSString key , uint ? value )
376
374
{
377
375
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
378
- Dictionary [ key ] = new NSNumber ( value . Value ) ;
376
+ Dictionary [ key ! ] = new NSNumber ( value ! . Value ) ;
379
377
}
380
378
381
379
#if XAMCORE_2_0
382
380
protected void SetNumberValue ( NSString key , nint ? value )
383
381
{
384
382
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
385
- Dictionary [ key ] = new NSNumber ( value . Value ) ;
383
+ Dictionary [ key ! ] = new NSNumber ( value ! . Value ) ;
386
384
}
387
385
388
386
protected void SetNumberValue ( NSString key , nuint ? value )
389
387
{
390
388
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
391
- Dictionary [ key ] = new NSNumber ( value . Value ) ;
389
+ Dictionary [ key ! ] = new NSNumber ( value ! . Value ) ;
392
390
}
393
391
#endif
394
392
395
393
protected void SetNumberValue ( NSString key , long ? value )
396
394
{
397
395
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
398
- Dictionary [ key ] = new NSNumber ( value . Value ) ;
396
+ Dictionary [ key ! ] = new NSNumber ( value ! . Value ) ;
399
397
}
400
398
401
399
protected void SetNumberValue ( NSString key , float ? value )
402
400
{
403
401
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
404
- Dictionary [ key ] = new NSNumber ( value . Value ) ;
402
+ Dictionary [ key ! ] = new NSNumber ( value ! . Value ) ;
405
403
}
406
404
407
405
protected void SetNumberValue ( NSString key , double ? value )
408
406
{
409
407
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
410
- Dictionary [ key ] = new NSNumber ( value . Value ) ;
408
+ Dictionary [ key ! ] = new NSNumber ( value ! . Value ) ;
411
409
}
412
410
413
411
#endregion
414
412
415
413
#region Sets NSString value
416
414
417
- protected void SetStringValue ( NSString key , string value )
415
+ protected void SetStringValue ( NSString key , string ? value )
418
416
{
419
- SetStringValue ( key , value == null ? ( NSString ) null : new NSString ( value ) ) ;
417
+ SetStringValue ( key , value == null ? ( NSString ) null ! : new NSString ( value ) ) ;
420
418
}
421
419
422
- protected void SetStringValue ( NSString key , NSString value )
420
+ protected void SetStringValue ( NSString key , NSString ? value )
423
421
{
424
422
if ( NullCheckAndRemoveKey ( key , value == null ) )
425
- Dictionary [ key ] = value ;
423
+ Dictionary [ key ! ] = value ;
426
424
}
427
425
428
426
#endregion
429
427
430
428
#region Sets Native value
431
429
432
- protected void SetNativeValue ( NSString key , INativeObject value , bool removeNullValue = true )
430
+ protected void SetNativeValue ( NSString key , INativeObject ? value , bool removeNullValue = true )
433
431
{
434
432
if ( NullCheckAndRemoveKey ( key , removeNullValue && value == null ) )
435
433
CFMutableDictionary . SetValue ( Dictionary . Handle , key . Handle , value == null ? IntPtr . Zero : value . Handle ) ;
@@ -451,26 +449,26 @@ protected void RemoveValue (NSString key)
451
449
protected void SetCGRectValue ( NSString key , CGRect ? value )
452
450
{
453
451
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
454
- Dictionary [ key ] = value . Value . ToDictionary ( ) ;
452
+ Dictionary [ key ! ] = value ! . Value . ToDictionary ( ) ;
455
453
}
456
454
457
455
protected void SetCGSizeValue ( NSString key , CGSize ? value )
458
456
{
459
457
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
460
- Dictionary [ key ] = value . Value . ToDictionary ( ) ;
458
+ Dictionary [ key ! ] = value ! . Value . ToDictionary ( ) ;
461
459
}
462
460
463
461
protected void SetCGPointValue ( NSString key , CGPoint ? value )
464
462
{
465
463
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
466
- Dictionary [ key ] = value . Value . ToDictionary ( ) ;
464
+ Dictionary [ key ! ] = value ! . Value . ToDictionary ( ) ;
467
465
}
468
466
#endif // XAMCORE_2_0
469
467
#if ! WATCH
470
468
protected void SetCMTimeValue ( NSString key , CMTime ? value )
471
469
{
472
470
if ( NullCheckAndRemoveKey ( key , ! value . HasValue ) )
473
- Dictionary [ key ] = value . Value . ToDictionary ( ) ;
471
+ Dictionary [ key ! ] = value ! . Value . ToDictionary ( ) ;
474
472
}
475
473
#endif //!WATCH
476
474
#endregion
@@ -482,14 +480,14 @@ static class DictionaryContainerHelper {
482
480
483
481
// helper to avoid the (common pattern)
484
482
// var p = x == null ? IntPtr.Zero : h.Dictionary.Handle;
485
- static public IntPtr GetHandle ( this DictionaryContainer self )
483
+ static public IntPtr GetHandle ( this DictionaryContainer ? self )
486
484
{
487
485
return self == null ? IntPtr . Zero : self . Dictionary . Handle ;
488
486
}
489
487
490
488
// helper to avoid the (common pattern)
491
489
// var p = x == null ? null : x.Dictionary;
492
- static public NSDictionary GetDictionary ( this DictionaryContainer self )
490
+ static public NSDictionary ? GetDictionary ( this DictionaryContainer ? self )
493
491
{
494
492
return self == null ? null : self . Dictionary ;
495
493
}
0 commit comments