22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5- #nullable disable
6-
75// Description: Specifies that the whitespace surrounding an element should be trimmed.
86
97using System ;
1311using System . Diagnostics ;
1412#if SYSTEM_XAML
1513using System . Xaml . Replacements ;
14+ #else
15+ #nullable disable
16+ #pragma warning disable CS8632
1617#endif
1718
1819#if PBTCOMPILER
@@ -114,26 +115,21 @@ internal static Type GetConverterType(MemberInfo memberInfo)
114115 return converterType ;
115116 }
116117#endif
117- internal static Type GetConverterType ( Type type )
118+ internal static Type ? GetConverterType ( Type type )
118119 {
119120 Debug . Assert ( null != type , "Null passed for type to GetConverterType" ) ;
120121
121- Type converterType = null ;
122-
123122 // 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 ) ;
125124
126- if ( converterType == null )
127- {
128- converterType = GetConverterTypeFromName ( converterName ) ;
129- }
125+ converterType ??= GetConverterTypeFromName ( converterName ) ;
130126
131127 return converterType ;
132128 }
133129
134- private static Type GetConverterTypeFromName ( string converterName )
130+ private static Type ? GetConverterTypeFromName ( string ? converterName )
135131 {
136- Type converterType = null ;
132+ Type ? converterType = null ;
137133
138134 if ( ! string . IsNullOrEmpty ( converterName ) )
139135 {
@@ -251,58 +247,58 @@ internal static Type GetCoreConverterTypeFromCustomType(Type type)
251247 }
252248#endif
253249#if ! PBTCOMPILER
254- private static TypeConverter GetCoreConverterFromCoreType ( Type type )
250+ private static TypeConverter ? GetCoreConverterFromCoreType ( Type type )
255251 {
256- TypeConverter typeConverter = null ;
257- if ( type == typeof ( Int32 ) )
252+ TypeConverter ? typeConverter = null ;
253+ if ( type == typeof ( int ) )
258254 {
259255 typeConverter = new System . ComponentModel . Int32Converter ( ) ;
260256 }
261- else if ( type == typeof ( Int16 ) )
257+ else if ( type == typeof ( short ) )
262258 {
263259 typeConverter = new System . ComponentModel . Int16Converter ( ) ;
264260 }
265- else if ( type == typeof ( Int64 ) )
261+ else if ( type == typeof ( long ) )
266262 {
267263 typeConverter = new System . ComponentModel . Int64Converter ( ) ;
268264 }
269- else if ( type == typeof ( UInt32 ) )
265+ else if ( type == typeof ( uint ) )
270266 {
271267 typeConverter = new System . ComponentModel . UInt32Converter ( ) ;
272268 }
273- else if ( type == typeof ( UInt16 ) )
269+ else if ( type == typeof ( ushort ) )
274270 {
275271 typeConverter = new System . ComponentModel . UInt16Converter ( ) ;
276272 }
277- else if ( type == typeof ( UInt64 ) )
273+ else if ( type == typeof ( ulong ) )
278274 {
279275 typeConverter = new System . ComponentModel . UInt64Converter ( ) ;
280276 }
281- else if ( type == typeof ( Boolean ) )
277+ else if ( type == typeof ( bool ) )
282278 {
283279 typeConverter = new System . ComponentModel . BooleanConverter ( ) ;
284280 }
285- else if ( type == typeof ( Double ) )
281+ else if ( type == typeof ( double ) )
286282 {
287283 typeConverter = new System . ComponentModel . DoubleConverter ( ) ;
288284 }
289- else if ( type == typeof ( Single ) )
285+ else if ( type == typeof ( float ) )
290286 {
291287 typeConverter = new System . ComponentModel . SingleConverter ( ) ;
292288 }
293- else if ( type == typeof ( Byte ) )
289+ else if ( type == typeof ( byte ) )
294290 {
295291 typeConverter = new System . ComponentModel . ByteConverter ( ) ;
296292 }
297- else if ( type == typeof ( SByte ) )
293+ else if ( type == typeof ( sbyte ) )
298294 {
299295 typeConverter = new System . ComponentModel . SByteConverter ( ) ;
300296 }
301- else if ( type == typeof ( Char ) )
297+ else if ( type == typeof ( char ) )
302298 {
303299 typeConverter = new System . ComponentModel . CharConverter ( ) ;
304300 }
305- else if ( type == typeof ( Decimal ) )
301+ else if ( type == typeof ( decimal ) )
306302 {
307303 typeConverter = new System . ComponentModel . DecimalConverter ( ) ;
308304 }
@@ -314,7 +310,7 @@ private static TypeConverter GetCoreConverterFromCoreType(Type type)
314310 {
315311 typeConverter = new System . ComponentModel . GuidConverter ( ) ;
316312 }
317- else if ( type == typeof ( String ) )
313+ else if ( type == typeof ( string ) )
318314 {
319315 typeConverter = new System . ComponentModel . StringConverter ( ) ;
320316 }
@@ -345,64 +341,64 @@ private static TypeConverter GetCoreConverterFromCoreType(Type type)
345341 return typeConverter ;
346342 }
347343
348- internal static TypeConverter GetCoreConverterFromCustomType ( Type type )
344+ internal static TypeConverter ? GetCoreConverterFromCustomType ( Type type )
349345 {
350- TypeConverter typeConverter = null ;
346+ TypeConverter ? typeConverter = null ;
351347 if ( type . IsEnum )
352348 {
353349 // Need to handle Enums types specially as they require a ctor that
354350 // takes the underlying type.
355351 typeConverter = new System . ComponentModel . EnumConverter ( type ) ;
356352 }
357- else if ( typeof ( Int32 ) . IsAssignableFrom ( type ) )
353+ else if ( typeof ( int ) . IsAssignableFrom ( type ) )
358354 {
359355 typeConverter = new System . ComponentModel . Int32Converter ( ) ;
360356 }
361- else if ( typeof ( Int16 ) . IsAssignableFrom ( type ) )
357+ else if ( typeof ( short ) . IsAssignableFrom ( type ) )
362358 {
363359 typeConverter = new System . ComponentModel . Int16Converter ( ) ;
364360 }
365- else if ( typeof ( Int64 ) . IsAssignableFrom ( type ) )
361+ else if ( typeof ( long ) . IsAssignableFrom ( type ) )
366362 {
367363 typeConverter = new System . ComponentModel . Int64Converter ( ) ;
368364 }
369- else if ( typeof ( UInt32 ) . IsAssignableFrom ( type ) )
365+ else if ( typeof ( uint ) . IsAssignableFrom ( type ) )
370366 {
371367 typeConverter = new System . ComponentModel . UInt32Converter ( ) ;
372368 }
373- else if ( typeof ( UInt16 ) . IsAssignableFrom ( type ) )
369+ else if ( typeof ( ushort ) . IsAssignableFrom ( type ) )
374370 {
375371 typeConverter = new System . ComponentModel . UInt16Converter ( ) ;
376372 }
377- else if ( typeof ( UInt64 ) . IsAssignableFrom ( type ) )
373+ else if ( typeof ( ulong ) . IsAssignableFrom ( type ) )
378374 {
379375 typeConverter = new System . ComponentModel . UInt64Converter ( ) ;
380376 }
381- else if ( typeof ( Boolean ) . IsAssignableFrom ( type ) )
377+ else if ( typeof ( bool ) . IsAssignableFrom ( type ) )
382378 {
383379 typeConverter = new System . ComponentModel . BooleanConverter ( ) ;
384380 }
385- else if ( typeof ( Double ) . IsAssignableFrom ( type ) )
381+ else if ( typeof ( double ) . IsAssignableFrom ( type ) )
386382 {
387383 typeConverter = new System . ComponentModel . DoubleConverter ( ) ;
388384 }
389- else if ( typeof ( Single ) . IsAssignableFrom ( type ) )
385+ else if ( typeof ( float ) . IsAssignableFrom ( type ) )
390386 {
391387 typeConverter = new System . ComponentModel . SingleConverter ( ) ;
392388 }
393- else if ( typeof ( Byte ) . IsAssignableFrom ( type ) )
389+ else if ( typeof ( byte ) . IsAssignableFrom ( type ) )
394390 {
395391 typeConverter = new System . ComponentModel . ByteConverter ( ) ;
396392 }
397- else if ( typeof ( SByte ) . IsAssignableFrom ( type ) )
393+ else if ( typeof ( sbyte ) . IsAssignableFrom ( type ) )
398394 {
399395 typeConverter = new System . ComponentModel . SByteConverter ( ) ;
400396 }
401- else if ( typeof ( Char ) . IsAssignableFrom ( type ) )
397+ else if ( typeof ( char ) . IsAssignableFrom ( type ) )
402398 {
403399 typeConverter = new System . ComponentModel . CharConverter ( ) ;
404400 }
405- else if ( typeof ( Decimal ) . IsAssignableFrom ( type ) )
401+ else if ( typeof ( decimal ) . IsAssignableFrom ( type ) )
406402 {
407403 typeConverter = new System . ComponentModel . DecimalConverter ( ) ;
408404 }
@@ -414,7 +410,7 @@ internal static TypeConverter GetCoreConverterFromCustomType(Type type)
414410 {
415411 typeConverter = new System . ComponentModel . GuidConverter ( ) ;
416412 }
417- else if ( typeof ( String ) . IsAssignableFrom ( type ) )
413+ else if ( typeof ( string ) . IsAssignableFrom ( type ) )
418414 {
419415 typeConverter = new System . ComponentModel . StringConverter ( ) ;
420416 }
@@ -458,11 +454,11 @@ internal static TypeConverter GetTypeConverter(Type type)
458454 {
459455 ArgumentNullException . ThrowIfNull ( type ) ;
460456
461- TypeConverter typeConverter = GetCoreConverterFromCoreType ( type ) ;
457+ TypeConverter ? typeConverter = GetCoreConverterFromCoreType ( type ) ;
462458
463459 if ( typeConverter == null )
464460 {
465- Type converterType = GetConverterType ( type ) ;
461+ Type ? converterType = GetConverterType ( type ) ;
466462 if ( converterType != null )
467463 {
468464 typeConverter = Activator . CreateInstance ( converterType ,
@@ -476,10 +472,7 @@ internal static TypeConverter GetTypeConverter(Type type)
476472 typeConverter = GetCoreConverterFromCustomType ( type ) ;
477473 }
478474
479- if ( typeConverter == null )
480- {
481- typeConverter = new TypeConverter ( ) ;
482- }
475+ typeConverter ??= new TypeConverter ( ) ;
483476 }
484477
485478 return typeConverter ;
0 commit comments