/// <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); }
/// <summary> /// Parses a row from the specified <paramref name="obj"/>. /// </summary> /// <param name="section">The parent section of the row.</param> /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> public static GridRow Parse(GridSection section, JObject obj) { // Some input validation if (obj == null) { throw new ArgumentNullException("obj"); } // Parse basic properties GridRow row = new GridRow(obj) { Section = section, Id = obj.GetString("id"), Alias = obj.GetString("alias"), Label = obj.GetString("label"), Name = obj.GetString("name") }; // Parse the areas row.Areas = obj.GetArray("areas", x => GridArea.Parse(row, x)) ?? new GridArea[0]; // Update "PreviousArea" and "NextArea" properties for (int i = 1; i < row.Areas.Length; i++) { row.Areas[i - 1].NextArea = row.Areas[i]; row.Areas[i].PreviousArea = row.Areas[i - 1]; } // Return the row return(row); }
public static GridDataModel Parse(JObject obj) { if (obj == null) { return(null); } return(new GridDataModel(obj) { Raw = obj.ToString(), Name = obj.GetString("name"), Sections = obj.GetArray("sections", x => GridSection.Parse(null, obj)) ?? new GridSection[0] }); }
/// <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; }
// ReSharper restore InconsistentNaming #endregion #endregion #region Constructors private GridDataModel(JObject obj) : base(obj) { Sections = new GridSection[0]; IsValid = false; }
/// <summary> /// Parses a row from the specified <code>obj</code>. /// </summary> /// <param name="section">The parent section of the row.</param> /// <param name="obj">The instance of <code>JObject</code> to be parsed.</param> public static GridRow Parse(GridSection section, JObject obj) { // Some input validation if (obj == null) throw new ArgumentNullException("obj"); // Parse basic properties GridRow row = new GridRow(obj) { Section = section, Id = obj.GetString("id"), Alias = obj.GetString("alias"), Name = obj.GetString("name"), Styles = obj.GetObject("styles", GridDictionary.Parse), Config = obj.GetObject("config", GridDictionary.Parse) }; // Parse the areas row.Areas = obj.GetArray("areas", x => GridArea.Parse(row, x)) ?? new GridArea[0]; // Update "PreviousArea" and "NextArea" properties for (int i = 1; i < row.Areas.Length; i++) { row.Areas[i - 1].NextArea = row.Areas[i]; row.Areas[i].PreviousArea = row.Areas[i - 1]; } // Return the row return row; }