11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
3- // See the LICENSE file in the project root for more information.
43
54using System . ComponentModel ;
65using System . ComponentModel . Design . Serialization ;
@@ -29,7 +28,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext td, Type t)
2928 /// <param name="context">ITypeDescriptorContext</param>
3029 /// <param name="destinationType">Type to convert to</param>
3130 /// <returns>true if conversion is possible</returns>
32- public override bool CanConvertTo ( ITypeDescriptorContext context , Type destinationType )
31+ public override bool CanConvertTo ( ITypeDescriptorContext context , Type destinationType )
3332 {
3433 return destinationType == typeof ( InstanceDescriptor ) || base . CanConvertTo ( context , destinationType ) ;
3534 }
@@ -39,12 +38,7 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati
3938 ///</summary>
4039 public static new object ConvertFromString ( string value )
4140 {
42- if ( null == value )
43- {
44- return null ;
45- }
46-
47- return Parsers . ParseColor ( value , null ) ;
41+ return value is not null ? Parsers . ParseColor ( value , null ) : null ;
4842 }
4943
5044 /// <summary>
@@ -61,8 +55,8 @@ public override object ConvertFrom(ITypeDescriptorContext td, CultureInfo ci, ob
6155
6256 if ( value is not string valueString )
6357 throw new ArgumentException ( SR . Format ( SR . General_BadType , nameof ( ConvertFrom ) , nameof ( value ) ) ) ;
64-
65- return Parsers . ParseColor ( valueString , ci , td ) ;
58+
59+ return Parsers . ParseColor ( valueString , ci , td ) ;
6660 }
6761
6862 /// <summary>
@@ -79,18 +73,17 @@ public override object ConvertFrom(ITypeDescriptorContext td, CultureInfo ci, ob
7973 /// <returns>converted value</returns>
8074 public override object ConvertTo ( ITypeDescriptorContext context , CultureInfo culture , object value , Type destinationType )
8175 {
82- if ( destinationType != null && value is Color )
76+ if ( destinationType != null && value is Color color )
8377 {
8478 if ( destinationType == typeof ( InstanceDescriptor ) )
8579 {
86- MethodInfo mi = typeof ( Color ) . GetMethod ( "FromArgb" , new Type [ ] { typeof ( byte ) , typeof ( byte ) , typeof ( byte ) , typeof ( byte ) } ) ;
87- Color c = ( Color ) value ;
88- return new InstanceDescriptor ( mi , new object [ ] { c . A , c . R , c . G , c . B } ) ;
80+ MethodInfo mi = typeof ( Color ) . GetMethod ( "FromArgb" , new Type [ ] { typeof ( byte ) , typeof ( byte ) , typeof ( byte ) , typeof ( byte ) } ) ;
81+
82+ return new InstanceDescriptor ( mi , new object [ ] { color . A , color . R , color . G , color . B } ) ;
8983 }
9084 else if ( destinationType == typeof ( string ) )
9185 {
92- Color c = ( Color ) value ;
93- return c . ToString ( culture ) ;
86+ return color . ToString ( culture ) ;
9487 }
9588 }
9689
0 commit comments