diff options
Diffstat (limited to '')
-rw-r--r-- | src/WixToolset.Data/IntermediateTupleDefinition.cs | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/WixToolset.Data/IntermediateTupleDefinition.cs b/src/WixToolset.Data/IntermediateTupleDefinition.cs index 5658cfe9..eb4ab12e 100644 --- a/src/WixToolset.Data/IntermediateTupleDefinition.cs +++ b/src/WixToolset.Data/IntermediateTupleDefinition.cs | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace WixToolset.Data | 3 | namespace WixToolset.Data |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using SimpleJson; | ||
6 | 7 | ||
7 | public class IntermediateTupleDefinition | 8 | public class IntermediateTupleDefinition |
8 | { | 9 | { |
@@ -23,7 +24,7 @@ namespace WixToolset.Data | |||
23 | this.FieldDefinitions = fieldDefinitions; | 24 | this.FieldDefinitions = fieldDefinitions; |
24 | this.StrongTupleType = strongTupleType ?? typeof(IntermediateTuple); | 25 | this.StrongTupleType = strongTupleType ?? typeof(IntermediateTuple); |
25 | #if DEBUG | 26 | #if DEBUG |
26 | if (!this.StrongTupleType.IsSubclassOf(typeof(IntermediateTuple))) throw new ArgumentException(nameof(strongTupleType)); | 27 | if (this.StrongTupleType != typeof(IntermediateTuple) && !this.StrongTupleType.IsSubclassOf(typeof(IntermediateTuple))) throw new ArgumentException(nameof(strongTupleType)); |
27 | #endif | 28 | #endif |
28 | } | 29 | } |
29 | 30 | ||
@@ -43,5 +44,52 @@ namespace WixToolset.Data | |||
43 | 44 | ||
44 | return result; | 45 | return result; |
45 | } | 46 | } |
47 | |||
48 | internal static IntermediateTupleDefinition Deserialize(JsonObject jsonObject) | ||
49 | { | ||
50 | var name = jsonObject.GetValueOrDefault<string>("name"); | ||
51 | var definitionsJson = jsonObject.GetValueOrDefault<JsonArray>("fields"); | ||
52 | |||
53 | var fieldDefinitions = new IntermediateFieldDefinition[definitionsJson.Count]; | ||
54 | |||
55 | for (var i = 0; i < definitionsJson.Count; ++i) | ||
56 | { | ||
57 | var definitionJson = (JsonObject)definitionsJson[i]; | ||
58 | var fieldName = definitionJson.GetValueOrDefault<string>("name"); | ||
59 | var fieldType = definitionJson.GetEnumOrDefault("type", IntermediateFieldType.String); | ||
60 | fieldDefinitions[i] = new IntermediateFieldDefinition(fieldName, fieldType); | ||
61 | } | ||
62 | |||
63 | return new IntermediateTupleDefinition(name, fieldDefinitions, null); | ||
64 | } | ||
65 | |||
66 | internal JsonObject Serialize() | ||
67 | { | ||
68 | var jsonObject = new JsonObject | ||
69 | { | ||
70 | { "name", this.Name } | ||
71 | }; | ||
72 | |||
73 | var fieldsJson = new JsonArray(this.FieldDefinitions.Length); | ||
74 | |||
75 | foreach (var fieldDefinition in this.FieldDefinitions) | ||
76 | { | ||
77 | var fieldJson = new JsonObject | ||
78 | { | ||
79 | { "name", fieldDefinition.Name }, | ||
80 | }; | ||
81 | |||
82 | if (fieldDefinition.Type != IntermediateFieldType.String) | ||
83 | { | ||
84 | fieldJson.Add("type", fieldDefinition.Type.ToString().ToLowerInvariant()); | ||
85 | } | ||
86 | |||
87 | fieldsJson.Add(fieldJson); | ||
88 | } | ||
89 | |||
90 | jsonObject.Add("fields", fieldsJson); | ||
91 | |||
92 | return jsonObject; | ||
93 | } | ||
46 | } | 94 | } |
47 | } | 95 | } |