Exemplo n.º 1
0
        void ReadJsonVariable(JsonReader reader, IEditableVariable destination)
        {
            bool isObjectVariable = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    var name = (string)reader.Value;
                    if (name == "@schema")
                    {
                        reader.Read();
                        if (destination.Schema.Id == (int)BuiltInSchema.Variable)
                        {
                            var schemaName = (string)reader.Value;
                            if (schemaName == Schema.BuiltIn[BuiltInSchema.Variable].Name)
                            {
                                isObjectVariable = true;
                            }
                            else
                            {
                                ((IEditableVariable)destination).DataSchema = schemaProvider.GetSchemaByName(schemaName);
                            }
                        }
                    }
                    else if (!isObjectVariable)
                    {
                        IEditable destinationField;
                        if (destination.Get <IEditableObject>().TryGetField((string)reader.Value, out destinationField))
                        {
                            ReadJson(reader, destinationField);
                        }
                        else
                        {
                            reader.Skip();
                        }
                    }
                    else
                    {
                        if (name == "DataSchemaId")
                        {
                            reader.Read();
                            destination.DataSchema = schemaProvider.GetSchemaById(Convert.ToInt32(reader.Value));
                        }
                        else if (name == "DataSchema")
                        {
                            reader.Read();
                            destination.DataSchema = schemaProvider.GetSchemaByName(reader.Value.ToString());
                        }
                        else if (name == "Data")
                        {
                            ReadJson(reader, destination.Get <IEditable>());
                        }
                    }
                }
                else
                {
                    if (ReadJsonValue(reader, destination))
                    {
                        return;
                    }
                }
            }
        }