2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
- #nullable disable
6
-
7
5
// Description: Specifies that the whitespace surrounding an element should be trimmed.
8
6
9
7
using System ;
13
11
using System . Diagnostics ;
14
12
#if SYSTEM_XAML
15
13
using System . Xaml . Replacements ;
14
+ #else
15
+ #nullable disable
16
+ #pragma warning disable CS8632
16
17
#endif
17
18
18
19
#if PBTCOMPILER
@@ -114,26 +115,21 @@ internal static Type GetConverterType(MemberInfo memberInfo)
114
115
return converterType ;
115
116
}
116
117
#endif
117
- internal static Type GetConverterType ( Type type )
118
+ internal static Type ? GetConverterType ( Type type )
118
119
{
119
120
Debug . Assert ( null != type , "Null passed for type to GetConverterType" ) ;
120
121
121
- Type converterType = null ;
122
-
123
122
// Try looking for the TypeConverter for the type using reflection.
124
- string converterName = ReflectionHelper . GetTypeConverterAttributeData ( type , out converterType ) ;
123
+ string ? converterName = ReflectionHelper . GetTypeConverterAttributeData ( type , out Type ? converterType ) ;
125
124
126
- if ( converterType == null )
127
- {
128
- converterType = GetConverterTypeFromName ( converterName ) ;
129
- }
125
+ converterType ??= GetConverterTypeFromName ( converterName ) ;
130
126
131
127
return converterType ;
132
128
}
133
129
134
- private static Type GetConverterTypeFromName ( string converterName )
130
+ private static Type ? GetConverterTypeFromName ( string ? converterName )
135
131
{
136
- Type converterType = null ;
132
+ Type ? converterType = null ;
137
133
138
134
if ( ! string . IsNullOrEmpty ( converterName ) )
139
135
{
@@ -251,58 +247,58 @@ internal static Type GetCoreConverterTypeFromCustomType(Type type)
251
247
}
252
248
#endif
253
249
#if ! PBTCOMPILER
254
- private static TypeConverter GetCoreConverterFromCoreType ( Type type )
250
+ private static TypeConverter ? GetCoreConverterFromCoreType ( Type type )
255
251
{
256
- TypeConverter typeConverter = null ;
257
- if ( type == typeof ( Int32 ) )
252
+ TypeConverter ? typeConverter = null ;
253
+ if ( type == typeof ( int ) )
258
254
{
259
255
typeConverter = new System . ComponentModel . Int32Converter ( ) ;
260
256
}
261
- else if ( type == typeof ( Int16 ) )
257
+ else if ( type == typeof ( short ) )
262
258
{
263
259
typeConverter = new System . ComponentModel . Int16Converter ( ) ;
264
260
}
265
- else if ( type == typeof ( Int64 ) )
261
+ else if ( type == typeof ( long ) )
266
262
{
267
263
typeConverter = new System . ComponentModel . Int64Converter ( ) ;
268
264
}
269
- else if ( type == typeof ( UInt32 ) )
265
+ else if ( type == typeof ( uint ) )
270
266
{
271
267
typeConverter = new System . ComponentModel . UInt32Converter ( ) ;
272
268
}
273
- else if ( type == typeof ( UInt16 ) )
269
+ else if ( type == typeof ( ushort ) )
274
270
{
275
271
typeConverter = new System . ComponentModel . UInt16Converter ( ) ;
276
272
}
277
- else if ( type == typeof ( UInt64 ) )
273
+ else if ( type == typeof ( ulong ) )
278
274
{
279
275
typeConverter = new System . ComponentModel . UInt64Converter ( ) ;
280
276
}
281
- else if ( type == typeof ( Boolean ) )
277
+ else if ( type == typeof ( bool ) )
282
278
{
283
279
typeConverter = new System . ComponentModel . BooleanConverter ( ) ;
284
280
}
285
- else if ( type == typeof ( Double ) )
281
+ else if ( type == typeof ( double ) )
286
282
{
287
283
typeConverter = new System . ComponentModel . DoubleConverter ( ) ;
288
284
}
289
- else if ( type == typeof ( Single ) )
285
+ else if ( type == typeof ( float ) )
290
286
{
291
287
typeConverter = new System . ComponentModel . SingleConverter ( ) ;
292
288
}
293
- else if ( type == typeof ( Byte ) )
289
+ else if ( type == typeof ( byte ) )
294
290
{
295
291
typeConverter = new System . ComponentModel . ByteConverter ( ) ;
296
292
}
297
- else if ( type == typeof ( SByte ) )
293
+ else if ( type == typeof ( sbyte ) )
298
294
{
299
295
typeConverter = new System . ComponentModel . SByteConverter ( ) ;
300
296
}
301
- else if ( type == typeof ( Char ) )
297
+ else if ( type == typeof ( char ) )
302
298
{
303
299
typeConverter = new System . ComponentModel . CharConverter ( ) ;
304
300
}
305
- else if ( type == typeof ( Decimal ) )
301
+ else if ( type == typeof ( decimal ) )
306
302
{
307
303
typeConverter = new System . ComponentModel . DecimalConverter ( ) ;
308
304
}
@@ -314,7 +310,7 @@ private static TypeConverter GetCoreConverterFromCoreType(Type type)
314
310
{
315
311
typeConverter = new System . ComponentModel . GuidConverter ( ) ;
316
312
}
317
- else if ( type == typeof ( String ) )
313
+ else if ( type == typeof ( string ) )
318
314
{
319
315
typeConverter = new System . ComponentModel . StringConverter ( ) ;
320
316
}
@@ -345,64 +341,64 @@ private static TypeConverter GetCoreConverterFromCoreType(Type type)
345
341
return typeConverter ;
346
342
}
347
343
348
- internal static TypeConverter GetCoreConverterFromCustomType ( Type type )
344
+ internal static TypeConverter ? GetCoreConverterFromCustomType ( Type type )
349
345
{
350
- TypeConverter typeConverter = null ;
346
+ TypeConverter ? typeConverter = null ;
351
347
if ( type . IsEnum )
352
348
{
353
349
// Need to handle Enums types specially as they require a ctor that
354
350
// takes the underlying type.
355
351
typeConverter = new System . ComponentModel . EnumConverter ( type ) ;
356
352
}
357
- else if ( typeof ( Int32 ) . IsAssignableFrom ( type ) )
353
+ else if ( typeof ( int ) . IsAssignableFrom ( type ) )
358
354
{
359
355
typeConverter = new System . ComponentModel . Int32Converter ( ) ;
360
356
}
361
- else if ( typeof ( Int16 ) . IsAssignableFrom ( type ) )
357
+ else if ( typeof ( short ) . IsAssignableFrom ( type ) )
362
358
{
363
359
typeConverter = new System . ComponentModel . Int16Converter ( ) ;
364
360
}
365
- else if ( typeof ( Int64 ) . IsAssignableFrom ( type ) )
361
+ else if ( typeof ( long ) . IsAssignableFrom ( type ) )
366
362
{
367
363
typeConverter = new System . ComponentModel . Int64Converter ( ) ;
368
364
}
369
- else if ( typeof ( UInt32 ) . IsAssignableFrom ( type ) )
365
+ else if ( typeof ( uint ) . IsAssignableFrom ( type ) )
370
366
{
371
367
typeConverter = new System . ComponentModel . UInt32Converter ( ) ;
372
368
}
373
- else if ( typeof ( UInt16 ) . IsAssignableFrom ( type ) )
369
+ else if ( typeof ( ushort ) . IsAssignableFrom ( type ) )
374
370
{
375
371
typeConverter = new System . ComponentModel . UInt16Converter ( ) ;
376
372
}
377
- else if ( typeof ( UInt64 ) . IsAssignableFrom ( type ) )
373
+ else if ( typeof ( ulong ) . IsAssignableFrom ( type ) )
378
374
{
379
375
typeConverter = new System . ComponentModel . UInt64Converter ( ) ;
380
376
}
381
- else if ( typeof ( Boolean ) . IsAssignableFrom ( type ) )
377
+ else if ( typeof ( bool ) . IsAssignableFrom ( type ) )
382
378
{
383
379
typeConverter = new System . ComponentModel . BooleanConverter ( ) ;
384
380
}
385
- else if ( typeof ( Double ) . IsAssignableFrom ( type ) )
381
+ else if ( typeof ( double ) . IsAssignableFrom ( type ) )
386
382
{
387
383
typeConverter = new System . ComponentModel . DoubleConverter ( ) ;
388
384
}
389
- else if ( typeof ( Single ) . IsAssignableFrom ( type ) )
385
+ else if ( typeof ( float ) . IsAssignableFrom ( type ) )
390
386
{
391
387
typeConverter = new System . ComponentModel . SingleConverter ( ) ;
392
388
}
393
- else if ( typeof ( Byte ) . IsAssignableFrom ( type ) )
389
+ else if ( typeof ( byte ) . IsAssignableFrom ( type ) )
394
390
{
395
391
typeConverter = new System . ComponentModel . ByteConverter ( ) ;
396
392
}
397
- else if ( typeof ( SByte ) . IsAssignableFrom ( type ) )
393
+ else if ( typeof ( sbyte ) . IsAssignableFrom ( type ) )
398
394
{
399
395
typeConverter = new System . ComponentModel . SByteConverter ( ) ;
400
396
}
401
- else if ( typeof ( Char ) . IsAssignableFrom ( type ) )
397
+ else if ( typeof ( char ) . IsAssignableFrom ( type ) )
402
398
{
403
399
typeConverter = new System . ComponentModel . CharConverter ( ) ;
404
400
}
405
- else if ( typeof ( Decimal ) . IsAssignableFrom ( type ) )
401
+ else if ( typeof ( decimal ) . IsAssignableFrom ( type ) )
406
402
{
407
403
typeConverter = new System . ComponentModel . DecimalConverter ( ) ;
408
404
}
@@ -414,7 +410,7 @@ internal static TypeConverter GetCoreConverterFromCustomType(Type type)
414
410
{
415
411
typeConverter = new System . ComponentModel . GuidConverter ( ) ;
416
412
}
417
- else if ( typeof ( String ) . IsAssignableFrom ( type ) )
413
+ else if ( typeof ( string ) . IsAssignableFrom ( type ) )
418
414
{
419
415
typeConverter = new System . ComponentModel . StringConverter ( ) ;
420
416
}
@@ -458,11 +454,11 @@ internal static TypeConverter GetTypeConverter(Type type)
458
454
{
459
455
ArgumentNullException . ThrowIfNull ( type ) ;
460
456
461
- TypeConverter typeConverter = GetCoreConverterFromCoreType ( type ) ;
457
+ TypeConverter ? typeConverter = GetCoreConverterFromCoreType ( type ) ;
462
458
463
459
if ( typeConverter == null )
464
460
{
465
- Type converterType = GetConverterType ( type ) ;
461
+ Type ? converterType = GetConverterType ( type ) ;
466
462
if ( converterType != null )
467
463
{
468
464
typeConverter = Activator . CreateInstance ( converterType ,
@@ -476,10 +472,7 @@ internal static TypeConverter GetTypeConverter(Type type)
476
472
typeConverter = GetCoreConverterFromCustomType ( type ) ;
477
473
}
478
474
479
- if ( typeConverter == null )
480
- {
481
- typeConverter = new TypeConverter ( ) ;
482
- }
475
+ typeConverter ??= new TypeConverter ( ) ;
483
476
}
484
477
485
478
return typeConverter ;
0 commit comments