23
23
using System . Collections . ObjectModel ;
24
24
using System . Globalization ;
25
25
26
+ #nullable enable
27
+
26
28
namespace OpenQA . Selenium . Remote
27
29
{
28
30
/// <summary>
@@ -56,14 +58,7 @@ public string BrowserName
56
58
{
57
59
get
58
60
{
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 ;
67
62
}
68
63
}
69
64
@@ -85,14 +80,7 @@ public string Version
85
80
{
86
81
get
87
82
{
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 ;
96
84
}
97
85
}
98
86
@@ -104,7 +92,7 @@ public bool AcceptInsecureCerts
104
92
get
105
93
{
106
94
bool acceptSSLCerts = false ;
107
- object capabilityValue = this . GetCapability ( CapabilityType . AcceptInsecureCertificates ) ;
95
+ object ? capabilityValue = this . GetCapability ( CapabilityType . AcceptInsecureCertificates ) ;
108
96
if ( capabilityValue != null )
109
97
{
110
98
acceptSSLCerts = ( bool ) capabilityValue ;
@@ -117,18 +105,12 @@ public bool AcceptInsecureCerts
117
105
/// <summary>
118
106
/// Gets the underlying Dictionary for a given set of capabilities.
119
107
/// </summary>
120
- IDictionary < string , object > IHasCapabilitiesDictionary . CapabilitiesDictionary
121
- {
122
- get { return this . CapabilitiesDictionary ; }
123
- }
108
+ IDictionary < string , object > IHasCapabilitiesDictionary . CapabilitiesDictionary => this . CapabilitiesDictionary ;
124
109
125
110
/// <summary>
126
111
/// Gets the underlying Dictionary for a given set of capabilities.
127
112
/// </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 ) ;
132
114
133
115
/// <summary>
134
116
/// Gets the capability value with the specified name.
@@ -142,12 +124,12 @@ public object this[string capabilityName]
142
124
{
143
125
get
144
126
{
145
- if ( ! this . capabilities . ContainsKey ( capabilityName ) )
127
+ if ( ! this . capabilities . TryGetValue ( capabilityName , out object ? capabilityValue ) )
146
128
{
147
129
throw new ArgumentException ( string . Format ( CultureInfo . InvariantCulture , "The capability {0} is not present in this set of capabilities" , capabilityName ) ) ;
148
130
}
149
131
150
- return this . capabilities [ capabilityName ] ;
132
+ return capabilityValue ;
151
133
}
152
134
}
153
135
@@ -167,20 +149,19 @@ public bool HasCapability(string capability)
167
149
/// <param name="capability">The capability to get.</param>
168
150
/// <returns>An object associated with the capability, or <see langword="null"/>
169
151
/// if the capability is not set on the browser.</returns>
170
- public object GetCapability ( string capability )
152
+ public object ? GetCapability ( string capability )
171
153
{
172
- object capabilityValue = null ;
173
- if ( this . capabilities . ContainsKey ( capability ) )
154
+ if ( this . capabilities . TryGetValue ( capability , out object ? capabilityValue ) )
174
155
{
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 )
178
157
{
179
- capabilityValue = Platform . FromString ( capabilityValue . ToString ( ) ) ;
158
+ capabilityValue = Platform . FromString ( capabilityValueString ) ;
180
159
}
160
+
161
+ return capabilityValue ;
181
162
}
182
163
183
- return capabilityValue ;
164
+ return null ;
184
165
}
185
166
186
167
/// <summary>
@@ -219,20 +200,19 @@ public override string ToString()
219
200
/// </summary>
220
201
/// <param name="obj">DesiredCapabilities you wish to compare</param>
221
202
/// <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 )
223
204
{
224
205
if ( this == obj )
225
206
{
226
207
return true ;
227
208
}
228
209
229
- DesiredCapabilities other = obj as DesiredCapabilities ;
230
- if ( other == null )
210
+ if ( obj is not DesiredCapabilities other )
231
211
{
232
212
return false ;
233
213
}
234
214
235
- if ( this . BrowserName != null ? this . BrowserName != other . BrowserName : other . BrowserName != null )
215
+ if ( this . BrowserName != other . BrowserName )
236
216
{
237
217
return false ;
238
218
}
@@ -242,7 +222,7 @@ public override bool Equals(object obj)
242
222
return false ;
243
223
}
244
224
245
- if ( this . Version != null ? this . Version != other . Version : other . Version != null )
225
+ if ( this . Version != other . Version )
246
226
{
247
227
return false ;
248
228
}
0 commit comments