diff options
Diffstat (limited to 'src/WixToolset.Data/IntermediateField.cs')
-rw-r--r-- | src/WixToolset.Data/IntermediateField.cs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/WixToolset.Data/IntermediateField.cs b/src/WixToolset.Data/IntermediateField.cs new file mode 100644 index 00000000..eba0e1ab --- /dev/null +++ b/src/WixToolset.Data/IntermediateField.cs | |||
@@ -0,0 +1,70 @@ | |||
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.Diagnostics; | ||
6 | using SimpleJson; | ||
7 | |||
8 | [DebuggerDisplay("Name={Name,nq} Type={Type} Value={Value.AsString()}")] | ||
9 | public class IntermediateField | ||
10 | { | ||
11 | public IntermediateField(IntermediateFieldDefinition definition) | ||
12 | { | ||
13 | this.Definition = definition; | ||
14 | } | ||
15 | |||
16 | public IntermediateFieldDefinition Definition { get; } | ||
17 | |||
18 | public string Name => this.Definition.Name; | ||
19 | |||
20 | public IntermediateFieldType Type => this.Definition.Type; | ||
21 | |||
22 | public string Context => this.Value?.Context; | ||
23 | |||
24 | public IntermediateFieldValue PreviousValue => this.Value?.PreviousValue; | ||
25 | |||
26 | internal IntermediateFieldValue Value { get; set; } | ||
27 | |||
28 | public static explicit operator bool(IntermediateField field) | ||
29 | { | ||
30 | return field.AsBool(); | ||
31 | } | ||
32 | |||
33 | public static explicit operator bool? (IntermediateField field) | ||
34 | { | ||
35 | return field.AsNullableBool(); | ||
36 | } | ||
37 | |||
38 | public static explicit operator int(IntermediateField field) | ||
39 | { | ||
40 | return field.AsNumber(); | ||
41 | } | ||
42 | |||
43 | public static explicit operator int? (IntermediateField field) | ||
44 | { | ||
45 | return field.AsNullableNumber(); | ||
46 | } | ||
47 | |||
48 | public static explicit operator string(IntermediateField field) | ||
49 | { | ||
50 | return field.AsString(); | ||
51 | } | ||
52 | |||
53 | internal static IntermediateField Deserialize(IntermediateFieldDefinition definition, JsonObject jsonObject) | ||
54 | { | ||
55 | var field = new IntermediateField(definition); | ||
56 | |||
57 | if (jsonObject != null) | ||
58 | { | ||
59 | field.Value = IntermediateFieldValue.Deserialize(jsonObject); | ||
60 | } | ||
61 | |||
62 | return field; | ||
63 | } | ||
64 | |||
65 | internal JsonObject Serialize() | ||
66 | { | ||
67 | return this.Value?.Serialize(); | ||
68 | } | ||
69 | } | ||
70 | } | ||