| 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 |
| 4 | { |
| 5 | using System; |
| 6 | using System.Diagnostics; |
| 7 | using SimpleJson; |
| 8 | |
| 9 | [DebuggerDisplay("Name={Name,nq} Type={Type} Value={Value?.AsString()}")] |
| 10 | public class IntermediateField |
| 11 | { |
| 12 | public IntermediateField(IntermediateFieldDefinition definition) => this.Definition = definition; |
| 13 | |
| 14 | public IntermediateFieldDefinition Definition { get; } |
| 15 | |
| 16 | public string Name => this.Definition.Name; |
| 17 | |
| 18 | public IntermediateFieldType Type => this.Definition.Type; |
| 19 | |
| 20 | public string Context => this.Value?.Context; |
| 21 | |
| 22 | public IntermediateFieldValue PreviousValue => this.Value?.PreviousValue; |
| 23 | |
| 24 | internal IntermediateFieldValue Value { get; set; } |
| 25 | |
| 26 | public static explicit operator bool(IntermediateField field) => field.AsBool(); |
| 27 | |
| 28 | public static explicit operator bool? (IntermediateField field) => field.AsNullableBool(); |
| 29 | |
| 30 | public static explicit operator long(IntermediateField field) => field.AsLargeNumber(); |
| 31 | |
| 32 | public static explicit operator long?(IntermediateField field) => field.AsNullableLargeNumber(); |
| 33 | |
| 34 | public static explicit operator int(IntermediateField field) => field.AsNumber(); |
| 35 | |
| 36 | public static explicit operator int? (IntermediateField field) => field.AsNullableNumber(); |
| 37 | |
| 38 | public static explicit operator string(IntermediateField field) => field.AsString(); |
| 39 | |
| 40 | internal static IntermediateField Deserialize(IntermediateFieldDefinition definition, Uri baseUri, JsonObject jsonObject) |
| 41 | { |
| 42 | IntermediateField field = null; |
| 43 | |
| 44 | if (jsonObject != null) |
| 45 | { |
| 46 | field = new IntermediateField(definition); |
| 47 | |
| 48 | field.Value = IntermediateFieldValue.Deserialize(jsonObject, baseUri, definition.Type); |
| 49 | } |
| 50 | |
| 51 | return field; |
| 52 | } |
| 53 | |
| 54 | internal JsonObject Serialize() => this.Value?.Serialize(); |
| 55 | } |
| 56 | } |