| 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.Core.Preprocess |
| 4 | { |
| 5 | /// <summary> |
| 6 | /// Context for an if statement in the preprocessor. |
| 7 | /// </summary> |
| 8 | internal class IfContext |
| 9 | { |
| 10 | private bool keep; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// Creates a default if context object, which are used for if's within an inactive preprocessor block |
| 14 | /// </summary> |
| 15 | public IfContext() |
| 16 | { |
| 17 | this.WasEverTrue = true; |
| 18 | this.IfState = IfState.If; |
| 19 | } |
| 20 | |
| 21 | /// <summary> |
| 22 | /// Creates an if context object. |
| 23 | /// </summary> |
| 24 | /// <param name="active">Flag if context is currently active.</param> |
| 25 | /// <param name="keep">Flag if context is currently true.</param> |
| 26 | /// <param name="state">State of context to start in.</param> |
| 27 | public IfContext(bool active, bool keep, IfState state) |
| 28 | { |
| 29 | this.Active = active; |
| 30 | this.keep = keep; |
| 31 | this.WasEverTrue = keep; |
| 32 | this.IfState = IfState.If; |
| 33 | } |
| 34 | |
| 35 | /// <summary> |
| 36 | /// Gets and sets if this if context is currently active. |
| 37 | /// </summary> |
| 38 | /// <value>true if context is active.</value> |
| 39 | public bool Active { get; set; } |
| 40 | |
| 41 | /// <summary> |
| 42 | /// Gets and sets if context is current true. |
| 43 | /// </summary> |
| 44 | /// <value>true if context is currently true.</value> |
| 45 | public bool IsTrue |
| 46 | { |
| 47 | get |
| 48 | { |
| 49 | return this.keep; |
| 50 | } |
| 51 | |
| 52 | set |
| 53 | { |
| 54 | this.keep = value; |
| 55 | if (this.keep) |
| 56 | { |
| 57 | this.WasEverTrue = true; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /// <summary> |
| 63 | /// Gets if the context was ever true. |
| 64 | /// </summary> |
| 65 | /// <value>True if context was ever true.</value> |
| 66 | public bool WasEverTrue { get; private set; } |
| 67 | |
| 68 | /// <summary> |
| 69 | /// Gets the current state of the if context. |
| 70 | /// </summary> |
| 71 | /// <value>Current state of context.</value> |
| 72 | public IfState IfState { get; set; } |
| 73 | } |
| 74 | } |