2323using System . Collections . ObjectModel ;
2424using System . Globalization ;
2525
26+ #nullable enable
27+
2628namespace OpenQA . Selenium . Remote
2729{
2830 /// <summary>
@@ -56,14 +58,7 @@ public string BrowserName
5658 {
5759 get
5860 {
59- string name = string . Empty ;
60- object capabilityValue = this . GetCapability ( CapabilityType . BrowserName ) ;
61- if ( capabilityValue != null )
62- {
63- name = capabilityValue . ToString ( ) ;
64- }
65-
66- return name ;
61+ return this . GetCapability ( CapabilityType . BrowserName ) ? . ToString ( ) ?? string . Empty ;
6762 }
6863 }
6964
@@ -85,14 +80,7 @@ public string Version
8580 {
8681 get
8782 {
88- string browserVersion = string . Empty ;
89- object capabilityValue = this . GetCapability ( CapabilityType . Version ) ;
90- if ( capabilityValue != null )
91- {
92- browserVersion = capabilityValue . ToString ( ) ;
93- }
94-
95- return browserVersion ;
83+ return this . GetCapability ( CapabilityType . Version ) ? . ToString ( ) ?? string . Empty ;
9684 }
9785 }
9886
@@ -104,7 +92,7 @@ public bool AcceptInsecureCerts
10492 get
10593 {
10694 bool acceptSSLCerts = false ;
107- object capabilityValue = this . GetCapability ( CapabilityType . AcceptInsecureCertificates ) ;
95+ object ? capabilityValue = this . GetCapability ( CapabilityType . AcceptInsecureCertificates ) ;
10896 if ( capabilityValue != null )
10997 {
11098 acceptSSLCerts = ( bool ) capabilityValue ;
@@ -117,18 +105,12 @@ public bool AcceptInsecureCerts
117105 /// <summary>
118106 /// Gets the underlying Dictionary for a given set of capabilities.
119107 /// </summary>
120- IDictionary < string , object > IHasCapabilitiesDictionary . CapabilitiesDictionary
121- {
122- get { return this . CapabilitiesDictionary ; }
123- }
108+ IDictionary < string , object > IHasCapabilitiesDictionary . CapabilitiesDictionary => this . CapabilitiesDictionary ;
124109
125110 /// <summary>
126111 /// Gets the underlying Dictionary for a given set of capabilities.
127112 /// </summary>
128- internal IDictionary < string , object > CapabilitiesDictionary
129- {
130- get { return new ReadOnlyDictionary < string , object > ( this . capabilities ) ; }
131- }
113+ internal IDictionary < string , object > CapabilitiesDictionary => new ReadOnlyDictionary < string , object > ( this . capabilities ) ;
132114
133115 /// <summary>
134116 /// Gets the capability value with the specified name.
@@ -142,12 +124,12 @@ public object this[string capabilityName]
142124 {
143125 get
144126 {
145- if ( ! this . capabilities . ContainsKey ( capabilityName ) )
127+ if ( ! this . capabilities . TryGetValue ( capabilityName , out object ? capabilityValue ) )
146128 {
147129 throw new ArgumentException ( string . Format ( CultureInfo . InvariantCulture , "The capability {0} is not present in this set of capabilities" , capabilityName ) ) ;
148130 }
149131
150- return this . capabilities [ capabilityName ] ;
132+ return capabilityValue ;
151133 }
152134 }
153135
@@ -167,20 +149,19 @@ public bool HasCapability(string capability)
167149 /// <param name="capability">The capability to get.</param>
168150 /// <returns>An object associated with the capability, or <see langword="null"/>
169151 /// if the capability is not set on the browser.</returns>
170- public object GetCapability ( string capability )
152+ public object ? GetCapability ( string capability )
171153 {
172- object capabilityValue = null ;
173- if ( this . capabilities . ContainsKey ( capability ) )
154+ if ( this . capabilities . TryGetValue ( capability , out object ? capabilityValue ) )
174155 {
175- capabilityValue = this . capabilities [ capability ] ;
176- string capabilityValueString = capabilityValue as string ;
177- if ( capability == CapabilityType . Platform && capabilityValueString != null )
156+ if ( capability == CapabilityType . Platform && capabilityValue is string capabilityValueString )
178157 {
179- capabilityValue = Platform . FromString ( capabilityValue . ToString ( ) ) ;
158+ capabilityValue = Platform . FromString ( capabilityValueString ) ;
180159 }
160+
161+ return capabilityValue ;
181162 }
182163
183- return capabilityValue ;
164+ return null ;
184165 }
185166
186167 /// <summary>
@@ -219,20 +200,19 @@ public override string ToString()
219200 /// </summary>
220201 /// <param name="obj">DesiredCapabilities you wish to compare</param>
221202 /// <returns>true if they are the same or false if they are not</returns>
222- public override bool Equals ( object obj )
203+ public override bool Equals ( object ? obj )
223204 {
224205 if ( this == obj )
225206 {
226207 return true ;
227208 }
228209
229- DesiredCapabilities other = obj as DesiredCapabilities ;
230- if ( other == null )
210+ if ( obj is not DesiredCapabilities other )
231211 {
232212 return false ;
233213 }
234214
235- if ( this . BrowserName != null ? this . BrowserName != other . BrowserName : other . BrowserName != null )
215+ if ( this . BrowserName != other . BrowserName )
236216 {
237217 return false ;
238218 }
@@ -242,7 +222,7 @@ public override bool Equals(object obj)
242222 return false ;
243223 }
244224
245- if ( this . Version != null ? this . Version != other . Version : other . Version != null )
225+ if ( this . Version != other . Version )
246226 {
247227 return false ;
248228 }
0 commit comments