| 1 | // 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. |
| 2 | |
| 3 | namespace WixToolset.Data.Bind |
| 4 | { |
| 5 | using SimpleJson; |
| 6 | |
| 7 | /// <summary> |
| 8 | /// Bind variable. |
| 9 | /// </summary> |
| 10 | public sealed class BindVariable |
| 11 | { |
| 12 | /// <summary> |
| 13 | /// Gets or sets the source line number. |
| 14 | /// </summary> |
| 15 | public SourceLineNumber SourceLineNumbers { get; set; } |
| 16 | |
| 17 | /// <summary> |
| 18 | /// Gets or sets the variable identifier. |
| 19 | /// </summary> |
| 20 | /// <value>The variable identifier.</value> |
| 21 | public string Id { get; set; } |
| 22 | |
| 23 | /// <summary> |
| 24 | /// Gets or sets the variable's value. |
| 25 | /// </summary> |
| 26 | /// <value>The variable's value.</value> |
| 27 | public string Value { get; set; } |
| 28 | |
| 29 | /// <summary> |
| 30 | /// Gets or sets whether this variable is overridable. |
| 31 | /// </summary> |
| 32 | /// <value>Whether this variable is overridable.</value> |
| 33 | public bool Overridable { get; set; } |
| 34 | |
| 35 | internal JsonObject Serialize() |
| 36 | { |
| 37 | var jsonObject = new JsonObject |
| 38 | { |
| 39 | { "name", this.Id }, |
| 40 | }; |
| 41 | |
| 42 | jsonObject.AddIsNotNullOrEmpty("value", this.Value); |
| 43 | jsonObject.AddNonDefaultValue("overridable", this.Overridable, false); |
| 44 | jsonObject.AddNonDefaultValue("ln", this.SourceLineNumbers?.Serialize()); |
| 45 | |
| 46 | return jsonObject; |
| 47 | } |
| 48 | |
| 49 | internal static BindVariable Deserialize(JsonObject jsonObject) |
| 50 | { |
| 51 | var variable = new BindVariable() |
| 52 | { |
| 53 | Id = jsonObject.GetValueOrDefault<string>("name"), |
| 54 | Value = jsonObject.GetValueOrDefault<string>("value"), |
| 55 | Overridable = jsonObject.GetValueOrDefault("overridable", false), |
| 56 | SourceLineNumbers = jsonObject.GetValueOrDefault<SourceLineNumber>("ln") |
| 57 | }; |
| 58 | |
| 59 | return variable; |
| 60 | } |
| 61 | } |
| 62 | } |