main
cs 91 lines 3.68 KB
Raw
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.Data;
7 using WixToolset.Extensibility.Services;
8
9 /// <summary>
10 /// Base class for creating a preprocessor extension.
11 /// </summary>
12 public abstract class BasePreprocessorExtension : IPreprocessorExtension
13 {
14 /// <summary>
15 /// Context for use by the extension.
16 /// </summary>
17 protected IPreprocessContext Context { get; private set; }
18
19 /// <summary>
20 /// Messaging for use by the extension.
21 /// </summary>
22 protected IMessaging Messaging { get; private set; }
23
24 /// <summary>
25 /// PreprocessHelper for use by the extension.
26 /// </summary>
27 protected IPreprocessHelper PreprocessHelper { get; private set; }
28
29 /// <summary>
30 /// Gets or sets the variable prefixes for the extension.
31 /// </summary>
32 /// <value>The variable prefixes for the extension.</value>
33 public string[] Prefixes { get; protected set; }
34
35 /// <summary>
36 /// Called at the beginning of the preprocessing of a source file.
37 /// </summary>
38 public virtual void PrePreprocess(IPreprocessContext context)
39 {
40 this.Context = context;
41
42 this.Messaging = context.ServiceProvider.GetService<IMessaging>();
43
44 this.PreprocessHelper = context.ServiceProvider.GetService<IPreprocessHelper>();
45 }
46
47 /// <summary>
48 /// Gets the value of a variable whose prefix matches the extension.
49 /// </summary>
50 /// <param name="prefix">The prefix of the variable to be processed by the extension.</param>
51 /// <param name="name">The name of the variable.</param>
52 /// <returns>The value of the variable or null if the variable is undefined.</returns>
53 public virtual string GetVariableValue(string prefix, string name)
54 {
55 return null;
56 }
57
58 /// <summary>
59 /// Evaluates a function defined in the extension.
60 /// </summary>
61 /// <param name="prefix">The prefix of the function to be processed by the extension.</param>
62 /// <param name="function">The name of the function.</param>
63 /// <param name="args">The list of arguments.</param>
64 /// <returns>The value of the function or null if the function is not defined.</returns>
65 public virtual string EvaluateFunction(string prefix, string function, string[] args)
66 {
67 return null;
68 }
69
70 /// <summary>
71 /// Processes a pragma defined in the extension.
72 /// </summary>
73 /// <param name="prefix">The prefix of the pragma to be processed by the extension.</param>
74 /// <param name="pragma">The name of the pragma.</param>
75 /// <param name="args">The pragma's arguments.</param>
76 /// <param name="parent">The parent node of the pragma.</param>
77 /// <returns>false if the pragma is not defined.</returns>
78 /// <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>
79 public virtual bool ProcessPragma(string prefix, string pragma, string args, XContainer parent)
80 {
81 return false;
82 }
83
84 /// <summary>
85 /// Called at the end of the preprocessing of a source file.
86 /// </summary>
87 public virtual void PostPreprocess(IPreprocessResult result)
88 {
89 }
90 }
91 }