// 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.
namespace WixToolset.Preprocess
{
using System;
///
/// Current state of the if context.
///
internal enum IfState
{
/// Context currently in unknown state.
Unknown,
/// Context currently inside if statement.
If,
/// Context currently inside elseif statement..
ElseIf,
/// Conext currently inside else statement.
Else,
}
///
/// Context for an if statement in the preprocessor.
///
internal sealed class IfContext
{
private bool active;
private bool keep;
private bool everKept;
private IfState state;
///
/// Creates a default if context object, which are used for if's within an inactive preprocessor block
///
public IfContext()
{
this.active = false;
this.keep = false;
this.everKept = true;
this.state = IfState.If;
}
///
/// Creates an if context object.
///
/// Flag if context is currently active.
/// Flag if context is currently true.
/// State of context to start in.
public IfContext(bool active, bool keep, IfState state)
{
this.active = active;
this.keep = keep;
this.everKept = keep;
this.state = state;
}
///
/// Gets and sets if this if context is currently active.
///
/// true if context is active.
public bool Active
{
get { return this.active; }
set { this.active = value; }
}
///
/// Gets and sets if context is current true.
///
/// true if context is currently true.
public bool IsTrue
{
get
{
return this.keep;
}
set
{
this.keep = value;
if (this.keep)
{
this.everKept = true;
}
}
}
///
/// Gets if the context was ever true.
///
/// True if context was ever true.
public bool WasEverTrue
{
get { return this.everKept; }
}
///
/// Gets the current state of the if context.
///
/// Current state of context.
public IfState IfState
{
get { return this.state; }
set { this.state = value; }
}
}
}