mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
b8896da54d
Includes various other DevTools fixes: - JavaScript "number"s are represented as doubles instead of longs - Headers are now correctly serialized / deserialized - DevToolsDomainErrorResponse is now correctly deserialized
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
// 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>(bool ignoreSuccess = false)
|
|
{
|
|
if (Success || ignoreSuccess)
|
|
{
|
|
#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 settings = new DataContractJsonSerializerSettings();
|
|
settings.UseSimpleDictionaryFormat = true;
|
|
|
|
var dcs = new DataContractJsonSerializer(typeof(T), settings);
|
|
return (T)dcs.ReadObject(ms);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
throw new DevToolsClientException(ResponseAsJsonString);
|
|
}
|
|
|
|
}
|
|
}
|