/// <summary> /// Deserializes the specified <paramref name="json"/> string into an instance of <see cref="GridDataModel"/>. /// </summary> /// <param name="json">The JSON string to be deserialized.</param> /// <param name="propertyTypeAlias">The alias of the property the Grid model is representing.</param> public static GridDataModel Deserialize(string json, string propertyTypeAlias) { // Validate the JSON if (json == null || !json.StartsWith("{") || !json.EndsWith("}")) { return(null); } // Deserialize the JSON JObject obj = JObject.Parse(json); // Parse basic properties GridDataModel model = new GridDataModel(obj) { Raw = json, Name = obj.GetString("name"), PropertyAlias = propertyTypeAlias }; // Parse the sections model.Sections = obj.GetArray("sections", x => GridSection.Parse(model, x)) ?? new GridSection[0]; // Return the model return(model); }
/// <summary> /// Parses a section from the specified <paramref name="model"/> and <paramref name="obj"/>. /// </summary> /// <param name="model">The parent model of the section.</param> /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> public static GridSection Parse(GridDataModel model, JObject obj) { // Some input validation if (obj == null) { throw new ArgumentNullException(nameof(obj)); } // Parse basic properties GridSection section = new GridSection(obj) { Model = model, Grid = obj.GetInt32("grid"), Name = model.Name }; // Parse the rows section.Rows = obj.GetArray("rows", x => GridRow.Parse(section, x)) ?? new GridRow[0]; // Update "PreviousRow" and "NextRow" properties for (int i = 1; i < section.Rows.Length; i++) { section.Rows[i - 1].NextRow = section.Rows[i]; section.Rows[i].PreviousRow = section.Rows[i - 1]; } // Return the section return(section); }
public object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) { // Get the value as a string string str = source as string; // Deserialize the string return(GridDataModel.Deserialize(str, propertyType.PropertyTypeAlias) ?? GridDataModel.GetEmptyModel(propertyType.PropertyTypeAlias)); }
/// <summary> /// Parses a section from the specified <code>obj</code>. /// </summary> /// <param name="model">The parent model of the section.</param> /// <param name="obj">The instance of <code>JObject</code> to be parsed.</param> public static GridSection Parse(GridDataModel model, JObject obj) { // Some input validation if (obj == null) throw new ArgumentNullException("obj"); // Parse basic properties GridSection section = new GridSection(obj) { Model = model, Grid = obj.GetInt32("grid") }; // Parse the rows section.Rows = obj.GetArray("rows", x => GridRow.Parse(section, x)) ?? new GridRow[0]; // Update "PreviousRow" and "NextRow" properties for (int i = 1; i < section.Rows.Length; i++) { section.Rows[i - 1].NextRow = section.Rows[i]; section.Rows[i].PreviousRow = section.Rows[i - 1]; } // Return the section return section; }
/// <summary> /// Deserializes the specified JSON string into an instance of <code>GridDataModel</code>. /// </summary> /// <param name="json">The JSON string to be deserialized.</param> /// <param name="propertyTypeAlias">The alias of the property the Grid model is representing.</param> public static GridDataModel Deserialize(string json, string propertyTypeAlias) { // Validate the JSON if (json == null || !json.StartsWith("{") || !json.EndsWith("}")) return null; // Deserialize the JSON JObject obj = JObject.Parse(json); // Parse basic properties GridDataModel model = new GridDataModel(obj) { Raw = json, Name = obj.GetString("name"), IsValid = true, PropertyAlias = propertyTypeAlias }; // Parse the sections model.Sections = obj.GetArray("sections", x => GridSection.Parse(model, x)) ?? new GridSection[0]; // Return the model return model; }
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview) { return(GridDataModel.Deserialize(source as string, propertyType.Alias, _config)); }