Projekt

Obecné

Profil

Stáhnout (1.3 KB) Statistiky
| Větev: | Tag: | Revize:
1
using System.Text.Json;
2
using System.Text.Json.Serialization;
3
using Newtonsoft.Json;
4
using JsonSerializer = System.Text.Json.JsonSerializer;
5

    
6
namespace LDClient.network.data {
7
    
8
    [JsonObject(MemberSerialization.OptIn)]
9
    public class Payload {
10

    
11
        [JsonPropertyName("username")]
12
        public string? UserName { get; set; }
13

    
14
        [JsonPropertyName("hostname")]
15
        public string? HostName { get; set; }
16

    
17
        [JsonPropertyName("timestamp")]
18
        public string? TimeStamp { get; set; }
19

    
20
        [JsonPropertyName("head_device")]
21
        public DebuggerInfo? HeadDevice { get; set; }
22

    
23

    
24
        [JsonPropertyName("body_device")]
25
        public DebuggerInfo?  BodyDevice { get; set; }
26
        
27
        [JsonPropertyName("status")]
28
        public ConnectionStatus Status { get; set; }
29

    
30

    
31
        public override string ToString() {
32
            return ParseToJson(this);
33
        }
34

    
35
        public string ParseToJson() {
36
            return Payload.ParseToJson(this);
37
        }
38

    
39
        public static string ParseToJson(Payload payload) {
40
            var options = new JsonSerializerOptions {
41
                Converters = {
42
                    new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
43
                }
44
            };
45

    
46
            return JsonSerializer.Serialize(payload, options);
47
        }
48
    }
49
}
(3-3/3)