Exemplo n.º 1
0
        bool ReadJsonValue(JsonReader reader, IEditable destination)
        {
            switch (reader.TokenType)
            {
            case JsonToken.PropertyName:
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    var name = (string)reader.Value;
                    if (name == "@schema")
                    {
                        reader.Read();
                    }
                    else
                    {
                        IEditable destinationField;
                        if (destination.Get <IEditableObject>().TryGetField(name, out destinationField))
                        {
                            ReadJson(reader, destinationField);
                        }
                        else
                        {
                            reader.Skip();
                        }
                    }
                }
                break;

            case JsonToken.StartArray:
                throw new Exception("StartArray token was unexpected");

            case JsonToken.EndArray:
                throw new Exception("EndArray token was unexpected");

            case JsonToken.EndObject:
                return(true);

            case JsonToken.Boolean:
            case JsonToken.Date:
            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.Null:
                destination.Set(reader.Value);
                return(true);

            case JsonToken.String:
                if (destination.Schema.DataType == DataType.Binary)
                {
                    destination.Set(Convert.FromBase64String((string)reader.Value));
                }
                //else if (destination.Schema.DataType == DataType.ItemPath)
                //destination.Set(HierarchyIdExtensions.Read(Convert.FromBase64String((string)reader.Value)));
                else
                {
                    destination.Set(reader.Value);
                }
                return(true);
            }
            return(false);
        }