diff options
Diffstat (limited to 'src/WixToolset.Extensibility/BasePreprocessorExtension.cs')
| -rw-r--r-- | src/WixToolset.Extensibility/BasePreprocessorExtension.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/WixToolset.Extensibility/BasePreprocessorExtension.cs b/src/WixToolset.Extensibility/BasePreprocessorExtension.cs new file mode 100644 index 00000000..acfcd5b9 --- /dev/null +++ b/src/WixToolset.Extensibility/BasePreprocessorExtension.cs | |||
| @@ -0,0 +1,84 @@ | |||
| 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.Extensibility | ||
| 4 | { | ||
| 5 | using System.Xml.Linq; | ||
| 6 | using WixToolset.Extensibility.Services; | ||
| 7 | |||
| 8 | /// <summary> | ||
| 9 | /// Base class for creating a preprocessor extension. | ||
| 10 | /// </summary> | ||
| 11 | public abstract class BasePreprocessorExtension : IPreprocessorExtension | ||
| 12 | { | ||
| 13 | /// <summary> | ||
| 14 | /// Context for use by the extension. | ||
| 15 | /// </summary> | ||
| 16 | protected IPreprocessContext Context { get; private set; } | ||
| 17 | |||
| 18 | /// <summary> | ||
| 19 | /// ParserHelper for use by the extension. | ||
| 20 | /// </summary> | ||
| 21 | protected IPreprocessHelper PreprocessHelper { get; private set; } | ||
| 22 | |||
| 23 | /// <summary> | ||
| 24 | /// Gets or sets the variable prefixes for the extension. | ||
| 25 | /// </summary> | ||
| 26 | /// <value>The variable prefixes for the extension.</value> | ||
| 27 | public string[] Prefixes { get; protected set; } | ||
| 28 | |||
| 29 | /// <summary> | ||
| 30 | /// Called at the beginning of the preprocessing of a source file. | ||
| 31 | /// </summary> | ||
| 32 | public virtual void PrePreprocess(IPreprocessContext context) | ||
| 33 | { | ||
| 34 | this.Context = context; | ||
| 35 | |||
| 36 | this.PreprocessHelper = context.ServiceProvider.GetService<IPreprocessHelper>(); | ||
| 37 | } | ||
| 38 | |||
| 39 | /// <summary> | ||
| 40 | /// Gets the value of a variable whose prefix matches the extension. | ||
| 41 | /// </summary> | ||
| 42 | /// <param name="prefix">The prefix of the variable to be processed by the extension.</param> | ||
| 43 | /// <param name="name">The name of the variable.</param> | ||
| 44 | /// <returns>The value of the variable or null if the variable is undefined.</returns> | ||
| 45 | public virtual string GetVariableValue(string prefix, string name) | ||
| 46 | { | ||
| 47 | return null; | ||
| 48 | } | ||
| 49 | |||
| 50 | /// <summary> | ||
| 51 | /// Evaluates a function defined in the extension. | ||
| 52 | /// </summary> | ||
| 53 | /// <param name="prefix">The prefix of the function to be processed by the extension.</param> | ||
| 54 | /// <param name="function">The name of the function.</param> | ||
| 55 | /// <param name="args">The list of arguments.</param> | ||
| 56 | /// <returns>The value of the function or null if the function is not defined.</returns> | ||
| 57 | public virtual string EvaluateFunction(string prefix, string function, string[] args) | ||
| 58 | { | ||
| 59 | return null; | ||
| 60 | } | ||
| 61 | |||
| 62 | /// <summary> | ||
| 63 | /// Processes a pragma defined in the extension. | ||
| 64 | /// </summary> | ||
| 65 | /// <param name="sourceLineNumbers">The location of this pragma's PI.</param> | ||
| 66 | /// <param name="prefix">The prefix of the pragma to be processed by the extension.</param> | ||
| 67 | /// <param name="pragma">The name of the pragma.</param> | ||
| 68 | /// <param name="args">The pragma's arguments.</param> | ||
| 69 | /// <param name="parent">The parent node of the pragma.</param> | ||
| 70 | /// <returns>false if the pragma is not defined.</returns> | ||
| 71 | /// <comments>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.</comments> | ||
| 72 | public virtual bool ProcessPragma(string prefix, string pragma, string args, XContainer parent) | ||
| 73 | { | ||
| 74 | return false; | ||
| 75 | } | ||
| 76 | |||
| 77 | /// <summary> | ||
| 78 | /// Called at the end of the preprocessing of a source file. | ||
| 79 | /// </summary> | ||
| 80 | public virtual void PostPreprocess(XDocument document) | ||
| 81 | { | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
