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