diff options
Diffstat (limited to 'src/WixToolset.Core/Preprocess/IfContext.cs')
-rw-r--r-- | src/WixToolset.Core/Preprocess/IfContext.cs | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Preprocess/IfContext.cs b/src/WixToolset.Core/Preprocess/IfContext.cs new file mode 100644 index 00000000..64b5bd91 --- /dev/null +++ b/src/WixToolset.Core/Preprocess/IfContext.cs | |||
@@ -0,0 +1,110 @@ | |||
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.Preprocess | ||
4 | { | ||
5 | using System; | ||
6 | |||
7 | /// <summary> | ||
8 | /// Current state of the if context. | ||
9 | /// </summary> | ||
10 | internal enum IfState | ||
11 | { | ||
12 | /// <summary>Context currently in unknown state.</summary> | ||
13 | Unknown, | ||
14 | |||
15 | /// <summary>Context currently inside if statement.</summary> | ||
16 | If, | ||
17 | |||
18 | /// <summary>Context currently inside elseif statement..</summary> | ||
19 | ElseIf, | ||
20 | |||
21 | /// <summary>Conext currently inside else statement.</summary> | ||
22 | Else, | ||
23 | } | ||
24 | |||
25 | /// <summary> | ||
26 | /// Context for an if statement in the preprocessor. | ||
27 | /// </summary> | ||
28 | internal sealed class IfContext | ||
29 | { | ||
30 | private bool active; | ||
31 | private bool keep; | ||
32 | private bool everKept; | ||
33 | private IfState state; | ||
34 | |||
35 | /// <summary> | ||
36 | /// Creates a default if context object, which are used for if's within an inactive preprocessor block | ||
37 | /// </summary> | ||
38 | public IfContext() | ||
39 | { | ||
40 | this.active = false; | ||
41 | this.keep = false; | ||
42 | this.everKept = true; | ||
43 | this.state = IfState.If; | ||
44 | } | ||
45 | |||
46 | /// <summary> | ||
47 | /// Creates an if context object. | ||
48 | /// </summary> | ||
49 | /// <param name="active">Flag if context is currently active.</param> | ||
50 | /// <param name="keep">Flag if context is currently true.</param> | ||
51 | /// <param name="state">State of context to start in.</param> | ||
52 | public IfContext(bool active, bool keep, IfState state) | ||
53 | { | ||
54 | this.active = active; | ||
55 | this.keep = keep; | ||
56 | this.everKept = keep; | ||
57 | this.state = state; | ||
58 | } | ||
59 | |||
60 | /// <summary> | ||
61 | /// Gets and sets if this if context is currently active. | ||
62 | /// </summary> | ||
63 | /// <value>true if context is active.</value> | ||
64 | public bool Active | ||
65 | { | ||
66 | get { return this.active; } | ||
67 | set { this.active = value; } | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Gets and sets if context is current true. | ||
72 | /// </summary> | ||
73 | /// <value>true if context is currently true.</value> | ||
74 | public bool IsTrue | ||
75 | { | ||
76 | get | ||
77 | { | ||
78 | return this.keep; | ||
79 | } | ||
80 | |||
81 | set | ||
82 | { | ||
83 | this.keep = value; | ||
84 | if (this.keep) | ||
85 | { | ||
86 | this.everKept = true; | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Gets if the context was ever true. | ||
93 | /// </summary> | ||
94 | /// <value>True if context was ever true.</value> | ||
95 | public bool WasEverTrue | ||
96 | { | ||
97 | get { return this.everKept; } | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// Gets the current state of the if context. | ||
102 | /// </summary> | ||
103 | /// <value>Current state of context.</value> | ||
104 | public IfState IfState | ||
105 | { | ||
106 | get { return this.state; } | ||
107 | set { this.state = value; } | ||
108 | } | ||
109 | } | ||
110 | } | ||