-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeBlenderExtensions.cs
51 lines (39 loc) · 1.53 KB
/
LeBlenderExtensions.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Our.TranslationManager.LeBlender
{
internal static class LeBlenderExtensions
{
/// <summary>
/// strip all non-object properties out of the value,
/// </summary>
/// <remarks>
/// removed the "propertiesOpen" value and any future non object values
/// that might be added to the value (ideally these values should be in config not value).
/// </remarks>
public static IEnumerable<Dictionary<string, LeBlenderProperties>> GetLeblenderModel(string value)
{
var json = JsonConvert.DeserializeObject<IEnumerable<Dictionary<string, JToken>>>(value);
var objectOnlyJson = json.Select(x =>
x.Where(y => y.Value.Type == JTokenType.Object).ToDictionary(k => k.Key, v => v.Value));
var stripped = JsonConvert.SerializeObject(objectOnlyJson);
return JsonConvert.DeserializeObject<IEnumerable<Dictionary<string, LeBlenderProperties>>>(stripped);
}
}
public class LeBlenderProperties
{
[JsonProperty("dataTypeGuid")]
public String DataTypeGuid { get; set; }
[JsonProperty("editorName")]
public String Name { get; set; }
[JsonProperty("editorAlias")]
public String Alias { get; set; }
[JsonProperty("value")]
public object Value { get; set; }
}
}