// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. namespace WixToolset.Data { using System; using SimpleJson; public class LocalizedControl { public LocalizedControl(string dialog, string control, int x, int y, int width, int height, int attribs, string text) { this.Dialog = dialog; this.Control = control; this.X = x; this.Y = y; this.Width = width; this.Height = height; this.Attributes = attribs; this.Text = text; } public string Dialog { get; } public string Control { get; } public int X { get; } public int Y { get; } public int Width { get; } public int Height { get; } public int Attributes { get; } public string Text { get; } /// /// Get key for a localized control. /// /// The localized control id. public string GetKey() => LocalizedControl.GetKey(this.Dialog, this.Control); /// /// Get key for a localized control. /// /// The optional id of the control's dialog. /// The id of the control. /// The localized control id. public static string GetKey(string dialog, string control) => String.Concat(dialog, "/", control); internal JsonObject Serialize() { var jsonObject = new JsonObject { { "dialog", this.Dialog }, }; jsonObject.AddIsNotNullOrEmpty("control", this.Control); jsonObject.AddNonDefaultValue("x", this.X, 0); jsonObject.AddNonDefaultValue("y", this.Y, 0); jsonObject.AddNonDefaultValue("width", this.Width, 0); jsonObject.AddNonDefaultValue("height", this.Height, 0); jsonObject.AddNonDefaultValue("attribs", this.Attributes, 0); jsonObject.AddIsNotNullOrEmpty("text", this.Text); return jsonObject; } internal static LocalizedControl Deserialize(JsonObject jsonObject) { var dialog = jsonObject.GetValueOrDefault("dialog"); var control = jsonObject.GetValueOrDefault("control"); var x = jsonObject.GetValueOrDefault("x", 0); var y = jsonObject.GetValueOrDefault("y", 0); var width = jsonObject.GetValueOrDefault("width", 0); var height = jsonObject.GetValueOrDefault("height", 0); var attribs = jsonObject.GetValueOrDefault("attribs", 0); var text = jsonObject.GetValueOrDefault("text"); return new LocalizedControl(dialog, control, x, y, width, height, attribs, text); } } }