| 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 WixToolset.Data; |
| 7 | using WixToolset.Data.Burn; |
| 8 | |
| 9 | public enum ExampleSymbolDefinitionType |
| 10 | { |
| 11 | Example, |
| 12 | ExampleSearch, |
| 13 | } |
| 14 | |
| 15 | public static class ExampleSymbolDefinitions |
| 16 | { |
| 17 | public static readonly IntermediateSymbolDefinition Example = new IntermediateSymbolDefinition( |
| 18 | ExampleSymbolDefinitionType.Example.ToString(), |
| 19 | new[] |
| 20 | { |
| 21 | new IntermediateFieldDefinition(nameof(ExampleSymbolFields.ComponentRef), IntermediateFieldType.String), |
| 22 | new IntermediateFieldDefinition(nameof(ExampleSymbolFields.Value), IntermediateFieldType.String), |
| 23 | }, |
| 24 | typeof(ExampleSymbol)); |
| 25 | |
| 26 | public static readonly IntermediateSymbolDefinition ExampleSearch = new IntermediateSymbolDefinition( |
| 27 | ExampleSymbolDefinitionType.ExampleSearch.ToString(), |
| 28 | new[] |
| 29 | { |
| 30 | new IntermediateFieldDefinition(nameof(ExampleSearchSymbolFields.SearchFor), IntermediateFieldType.String), |
| 31 | }, |
| 32 | typeof(ExampleSearchSymbol)); |
| 33 | |
| 34 | static ExampleSymbolDefinitions() |
| 35 | { |
| 36 | ExampleSearch.AddTag(BurnConstants.BootstrapperExtensionSearchSymbolDefinitionTag); |
| 37 | } |
| 38 | |
| 39 | public static bool TryGetSymbolType(string name, out ExampleSymbolDefinitionType type) |
| 40 | { |
| 41 | return Enum.TryParse(name, out type); |
| 42 | } |
| 43 | |
| 44 | public static IntermediateSymbolDefinition ByName(string name) |
| 45 | { |
| 46 | if (!TryGetSymbolType(name, out var type)) |
| 47 | { |
| 48 | return null; |
| 49 | } |
| 50 | return ByType(type); |
| 51 | } |
| 52 | |
| 53 | public static IntermediateSymbolDefinition ByType(ExampleSymbolDefinitionType type) |
| 54 | { |
| 55 | switch (type) |
| 56 | { |
| 57 | case ExampleSymbolDefinitionType.Example: |
| 58 | return ExampleSymbolDefinitions.Example; |
| 59 | |
| 60 | case ExampleSymbolDefinitionType.ExampleSearch: |
| 61 | return ExampleSymbolDefinitions.ExampleSearch; |
| 62 | |
| 63 | default: |
| 64 | throw new ArgumentOutOfRangeException(nameof(type)); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |