-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathDevToolsMethodResponse.cs
More file actions
61 lines (52 loc) · 1.77 KB
/
DevToolsMethodResponse.cs
File metadata and controls
61 lines (52 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright © 2020 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
namespace CefSharp.DevTools
{
/// <summary>
/// DevTools Method Response
/// </summary>
public class DevToolsMethodResponse
{
/// <summary>
/// MessageId
/// </summary>
public int MessageId { get; set; }
/// <summary>
/// Success
/// </summary>
public bool Success { get; set; }
/// <summary>
/// Method Response as Json string
/// </summary>
public string ResponseAsJsonString { get; set; }
internal T DeserializeJson<T>()
{
if (Success)
{
#if NETCOREAPP
var options = new System.Text.Json.JsonSerializerOptions
{
//AllowTrailingCommas = true,
PropertyNameCaseInsensitive = true,
IgnoreNullValues = true,
//PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase
};
options.Converters.Add(new Internals.Json.JsonEnumConverterFactory());
return System.Text.Json.JsonSerializer.Deserialize<T>(ResponseAsJsonString, options);
#else
var bytes = Encoding.UTF8.GetBytes(ResponseAsJsonString);
using (var ms = new MemoryStream(bytes))
{
var dcs = new DataContractJsonSerializer(typeof(T));
return (T)dcs.ReadObject(ms);
}
#endif
}
throw new DevToolsClientException(ResponseAsJsonString);
}
}
}