// 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.Extensibility
{
using System.Xml.Linq;
using WixToolset.Extensibility.Data;
using WixToolset.Extensibility.Services;
///
/// Base class for creating a preprocessor extension.
///
public abstract class BasePreprocessorExtension : IPreprocessorExtension
{
///
/// Context for use by the extension.
///
protected IPreprocessContext Context { get; private set; }
///
/// Messaging for use by the extension.
///
protected IMessaging Messaging { get; private set; }
///
/// PreprocessHelper for use by the extension.
///
protected IPreprocessHelper PreprocessHelper { get; private set; }
///
/// Gets or sets the variable prefixes for the extension.
///
/// The variable prefixes for the extension.
public string[] Prefixes { get; protected set; }
///
/// Called at the beginning of the preprocessing of a source file.
///
public virtual void PrePreprocess(IPreprocessContext context)
{
this.Context = context;
this.Messaging = context.ServiceProvider.GetService();
this.PreprocessHelper = context.ServiceProvider.GetService();
}
///
/// Gets the value of a variable whose prefix matches the extension.
///
/// The prefix of the variable to be processed by the extension.
/// The name of the variable.
/// The value of the variable or null if the variable is undefined.
public virtual string GetVariableValue(string prefix, string name)
{
return null;
}
///
/// Evaluates a function defined in the extension.
///
/// The prefix of the function to be processed by the extension.
/// The name of the function.
/// The list of arguments.
/// The value of the function or null if the function is not defined.
public virtual string EvaluateFunction(string prefix, string function, string[] args)
{
return null;
}
///
/// Processes a pragma defined in the extension.
///
/// The location of this pragma's PI.
/// The prefix of the pragma to be processed by the extension.
/// The name of the pragma.
/// The pragma's arguments.
/// The parent node of the pragma.
/// false if the pragma is not defined.
/// Don't return false for any condition except for unrecognized pragmas. Throw errors that are fatal to the compile. use core.OnMessage for warnings and messages.
public virtual bool ProcessPragma(string prefix, string pragma, string args, XContainer parent)
{
return false;
}
///
/// Called at the end of the preprocessing of a source file.
///
public virtual void PostPreprocess(IPreprocessResult result)
{
}
}
}