From 53e877183abe0dbbb623c39380101bc369e9f265 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 2 Dec 2017 00:44:45 -0800 Subject: Support tuples from extensions and make SourcePath a path instead of string --- src/WixToolset.Data/IntermediateTupleDefinition.cs | 50 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/WixToolset.Data/IntermediateTupleDefinition.cs') 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 @@ namespace WixToolset.Data { using System; + using SimpleJson; public class IntermediateTupleDefinition { @@ -23,7 +24,7 @@ namespace WixToolset.Data this.FieldDefinitions = fieldDefinitions; this.StrongTupleType = strongTupleType ?? typeof(IntermediateTuple); #if DEBUG - if (!this.StrongTupleType.IsSubclassOf(typeof(IntermediateTuple))) throw new ArgumentException(nameof(strongTupleType)); + if (this.StrongTupleType != typeof(IntermediateTuple) && !this.StrongTupleType.IsSubclassOf(typeof(IntermediateTuple))) throw new ArgumentException(nameof(strongTupleType)); #endif } @@ -43,5 +44,52 @@ namespace WixToolset.Data return result; } + + internal static IntermediateTupleDefinition Deserialize(JsonObject jsonObject) + { + var name = jsonObject.GetValueOrDefault("name"); + var definitionsJson = jsonObject.GetValueOrDefault("fields"); + + var fieldDefinitions = new IntermediateFieldDefinition[definitionsJson.Count]; + + for (var i = 0; i < definitionsJson.Count; ++i) + { + var definitionJson = (JsonObject)definitionsJson[i]; + var fieldName = definitionJson.GetValueOrDefault("name"); + var fieldType = definitionJson.GetEnumOrDefault("type", IntermediateFieldType.String); + fieldDefinitions[i] = new IntermediateFieldDefinition(fieldName, fieldType); + } + + return new IntermediateTupleDefinition(name, fieldDefinitions, null); + } + + internal JsonObject Serialize() + { + var jsonObject = new JsonObject + { + { "name", this.Name } + }; + + var fieldsJson = new JsonArray(this.FieldDefinitions.Length); + + foreach (var fieldDefinition in this.FieldDefinitions) + { + var fieldJson = new JsonObject + { + { "name", fieldDefinition.Name }, + }; + + if (fieldDefinition.Type != IntermediateFieldType.String) + { + fieldJson.Add("type", fieldDefinition.Type.ToString().ToLowerInvariant()); + } + + fieldsJson.Add(fieldJson); + } + + jsonObject.Add("fields", fieldsJson); + + return jsonObject; + } } } -- cgit v1.2.3-55-g6feb