diff options
Diffstat (limited to 'src/test/Example.Extension/ExampleCompilerExtension.cs')
-rw-r--r-- | src/test/Example.Extension/ExampleCompilerExtension.cs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/test/Example.Extension/ExampleCompilerExtension.cs b/src/test/Example.Extension/ExampleCompilerExtension.cs new file mode 100644 index 00000000..cd9e1fb9 --- /dev/null +++ b/src/test/Example.Extension/ExampleCompilerExtension.cs | |||
@@ -0,0 +1,81 @@ | |||
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 Example.Extension | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Xml.Linq; | ||
8 | using WixToolset.Data; | ||
9 | using WixToolset.Extensibility; | ||
10 | |||
11 | internal class ExampleCompilerExtension : BaseCompilerExtension | ||
12 | { | ||
13 | public override XNamespace Namespace => "http://www.example.com/scheams/v1/wxs"; | ||
14 | |||
15 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) | ||
16 | { | ||
17 | var processed = false; | ||
18 | |||
19 | switch (parentElement.Name.LocalName) | ||
20 | { | ||
21 | case "Component": | ||
22 | switch (element.Name.LocalName) | ||
23 | { | ||
24 | case "Example": | ||
25 | this.ParseExampleElement(intermediate, section, element); | ||
26 | processed = true; | ||
27 | break; | ||
28 | } | ||
29 | break; | ||
30 | } | ||
31 | |||
32 | if (!processed) | ||
33 | { | ||
34 | base.ParseElement(intermediate, section, parentElement, element, context); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | private void ParseExampleElement(Intermediate intermediate, IntermediateSection section, XElement element) | ||
39 | { | ||
40 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | ||
41 | Identifier id = null; | ||
42 | string value = null; | ||
43 | |||
44 | foreach (var attrib in element.Attributes()) | ||
45 | { | ||
46 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | ||
47 | { | ||
48 | switch (attrib.Name.LocalName) | ||
49 | { | ||
50 | case "Id": | ||
51 | id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); | ||
52 | break; | ||
53 | |||
54 | case "Value": | ||
55 | value = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
56 | break; | ||
57 | |||
58 | default: | ||
59 | this.ParseHelper.UnexpectedAttribute(element, attrib); | ||
60 | break; | ||
61 | } | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | this.ParseAttribute(intermediate, section, element, attrib, null); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | if (null == id) | ||
70 | { | ||
71 | //this.Messaging(WixErrors.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); | ||
72 | } | ||
73 | |||
74 | if (!this.Messaging.EncounteredError) | ||
75 | { | ||
76 | var tuple = this.ParseHelper.CreateRow(section, sourceLineNumbers, "Example", id); | ||
77 | tuple.Set(1, value); | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | } | ||