-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathJsonExtensions.cs
More file actions
57 lines (52 loc) · 1.7 KB
/
JsonExtensions.cs
File metadata and controls
57 lines (52 loc) · 1.7 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
using System;
using System.Collections.Generic;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using SharpHoundCommonLib.Enums;
namespace Sharphound
{
public class Credentials
{
public string Username { get; set; }
public string Password { get; set; }
}
public class CacheContractResolver : DefaultContractResolver
{
private static readonly CacheContractResolver Instance = new();
public static readonly JsonSerializerSettings Settings = new()
{
ContractResolver = Instance,
Converters = new List<JsonConverter> {new VersionConverter()}
};
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var prop = base.CreateProperty(member, memberSerialization);
if (!prop.Writable && (member as PropertyInfo)?.GetSetMethod(true) != null) {
prop.Writable = true;
}
return prop;
}
}
public class KindConvertor : JsonConverter<Label>
{
public override void WriteJson(JsonWriter writer, Label value, JsonSerializer serializer)
{
writer.WriteValue(value.ToString());
}
public override Label ReadJson(JsonReader reader, Type objectType, Label existingValue, bool hasExistingValue,
JsonSerializer serializer)
{
var s = (string) reader.Value;
if (Enum.TryParse(s, out Label label))
{
return label;
}
else
{
return Label.Base;
}
}
}
}