@@ -56,57 +56,69 @@ public Response(SessionId sessionId)
56
56
}
57
57
}
58
58
59
- private Response ( Dictionary < string , object > rawResponse )
59
+ /// <summary>
60
+ /// Returns a new <see cref="Response"/> from a JSON-encoded string.
61
+ /// </summary>
62
+ /// <param name="value">The JSON string to deserialize into a <see cref="Response"/>.</param>
63
+ /// <returns>A <see cref="Response"/> object described by the JSON string.</returns>
64
+ public static Response FromJson ( string value )
60
65
{
66
+ Dictionary < string , object > rawResponse = JsonSerializer . Deserialize < Dictionary < string , object > > ( value , s_jsonSerializerOptions )
67
+ ?? throw new WebDriverException ( "JSON success response returned \" null\" value" ) ;
68
+
69
+ var response = new Response ( ) ;
70
+
61
71
if ( rawResponse . ContainsKey ( "sessionId" ) )
62
72
{
63
73
if ( rawResponse [ "sessionId" ] != null )
64
74
{
65
- this . SessionId = rawResponse [ "sessionId" ] . ToString ( ) ;
75
+ response . SessionId = rawResponse [ "sessionId" ] . ToString ( ) ;
66
76
}
67
77
}
68
78
69
- if ( rawResponse . TryGetValue ( "value" , out object value ) )
79
+ if ( rawResponse . TryGetValue ( "value" , out object valueObj ) )
70
80
{
71
- this . Value = value ;
81
+ response . Value = valueObj ;
72
82
}
73
83
74
84
// If the returned object does *not* have a "value" property
75
85
// the response value should be the entirety of the response.
76
86
// TODO: Remove this if statement altogether; there should
77
87
// never be a spec-compliant response that does not contain a
78
88
// value property.
79
- if ( ! rawResponse . ContainsKey ( "value" ) && this . Value == null )
89
+ if ( ! rawResponse . ContainsKey ( "value" ) && response . Value == null )
80
90
{
81
91
// Special-case for the new session command, where the "capabilities"
82
92
// property of the response is the actual value we're interested in.
83
93
if ( rawResponse . ContainsKey ( "capabilities" ) )
84
94
{
85
- this . Value = rawResponse [ "capabilities" ] ;
95
+ response . Value = rawResponse [ "capabilities" ] ;
86
96
}
87
97
else
88
98
{
89
- this . Value = rawResponse ;
99
+ response . Value = rawResponse ;
90
100
}
91
101
}
92
102
93
- if ( this . Value is Dictionary < string , object > valueDictionary )
103
+ if ( response . Value is Dictionary < string , object > valueDictionary )
94
104
{
95
105
// Special case code for the new session command. If the response contains
96
106
// sessionId and capabilities properties, fix up the session ID and value members.
97
107
if ( valueDictionary . ContainsKey ( "sessionId" ) )
98
108
{
99
- this . SessionId = valueDictionary [ "sessionId" ] . ToString ( ) ;
109
+ response . SessionId = valueDictionary [ "sessionId" ] . ToString ( ) ;
100
110
if ( valueDictionary . TryGetValue ( "capabilities" , out object capabilities ) )
101
111
{
102
- this . Value = capabilities ;
112
+ response . Value = capabilities ;
103
113
}
104
114
else
105
115
{
106
- this . Value = valueDictionary [ "value" ] ;
116
+ response . Value = valueDictionary [ "value" ] ;
107
117
}
108
118
}
109
119
}
120
+
121
+ return response ;
110
122
}
111
123
112
124
/// <summary>
@@ -124,18 +136,6 @@ private Response(Dictionary<string, object> rawResponse)
124
136
/// </summary>
125
137
public WebDriverResult Status { get ; set ; }
126
138
127
- /// <summary>
128
- /// Returns a new <see cref="Response"/> from a JSON-encoded string.
129
- /// </summary>
130
- /// <param name="value">The JSON string to deserialize into a <see cref="Response"/>.</param>
131
- /// <returns>A <see cref="Response"/> object described by the JSON string.</returns>
132
- public static Response FromJson ( string value )
133
- {
134
- Dictionary < string , object > deserializedResponse = JsonSerializer . Deserialize < Dictionary < string , object > > ( value , s_jsonSerializerOptions )
135
- ?? throw new WebDriverException ( "JSON success response returned \" null\" value" ) ;
136
-
137
- return new Response ( deserializedResponse ) ;
138
- }
139
139
140
140
/// <summary>
141
141
/// Returns a new <see cref="Response"/> from a JSON-encoded string.
0 commit comments