예제 #1
0
        internal static IntermediateSymbol Deserialize(ISymbolDefinitionCreator creator, Uri baseUri, JsonObject jsonObject)
        {
            var definitionName        = jsonObject.GetValueOrDefault <string>("type");
            var idJson                = jsonObject.GetValueOrDefault <JsonObject>("id");
            var sourceLineNumbersJson = jsonObject.GetValueOrDefault <JsonObject>("ln");
            var fieldsJson            = jsonObject.GetValueOrDefault <JsonArray>("fields");
            var tagsJson              = jsonObject.GetValueOrDefault <JsonArray>("tags");

            var id = (idJson == null) ? null : Identifier.Deserialize(idJson);
            var sourceLineNumbers = (sourceLineNumbersJson == null) ? null : SourceLineNumber.Deserialize(sourceLineNumbersJson);

            // TODO: this isn't sufficient.
            if (!creator.TryGetSymbolDefinitionByName(definitionName, out var definition))
            {
                throw new WixException(ErrorMessages.UnknownSymbolType(definitionName));
            }

            var symbol = definition.CreateSymbol(sourceLineNumbers, id);

            for (var i = 0; i < fieldsJson.Count && i < symbol.Fields.Length; ++i)
            {
                if (fieldsJson[i] is JsonObject fieldJson)
                {
                    symbol.Fields[i] = IntermediateField.Deserialize(symbol.Definition.FieldDefinitions[i], baseUri, fieldJson);
                }
            }

            if (tagsJson == null || tagsJson.Count == 0)
            {
            }
            else if (tagsJson.Count == 1)
            {
                symbol.tags = (string)tagsJson[0];
            }
            else
            {
                var tags = new string[tagsJson.Count];

                for (var i = 0; i < tagsJson.Count; ++i)
                {
                    tags[i] = (string)tagsJson[i];
                }

                symbol.tags = tags;
            }

            return(symbol);
        }
예제 #2
0
        internal static IntermediateTuple Deserialize(ITupleDefinitionCreator creator, Uri baseUri, JsonObject jsonObject)
        {
            var definitionName        = jsonObject.GetValueOrDefault <string>("type");
            var idJson                = jsonObject.GetValueOrDefault <JsonObject>("id");
            var sourceLineNumbersJson = jsonObject.GetValueOrDefault <JsonObject>("ln");
            var fieldsJson            = jsonObject.GetValueOrDefault <JsonArray>("fields");

            var id = (idJson == null) ? null : Identifier.Deserialize(idJson);
            var sourceLineNumbers = (sourceLineNumbersJson == null) ? null : SourceLineNumber.Deserialize(sourceLineNumbersJson);

            creator.TryGetTupleDefinitionByName(definitionName, out var definition); // TODO: this isn't sufficient.
            var tuple = definition.CreateTuple(sourceLineNumbers, id);

            for (var i = 0; i < fieldsJson.Count; ++i)
            {
                if (tuple.Fields.Length > i && fieldsJson[i] is JsonObject fieldJson)
                {
                    tuple.Fields[i] = IntermediateField.Deserialize(tuple.Definition.FieldDefinitions[i], baseUri, fieldJson);
                }
            }

            return(tuple);
        }