aboutsummaryrefslogtreecommitdiff
path: root/src/test/Example.Extension/ExampleSymbolDefinitions.cs
blob: f13d716d22b361bf9e55f614ca89d5b9323f3f3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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.

namespace Example.Extension
{
    using System;
    using WixToolset.Data;
    using WixToolset.Data.Burn;

    public enum ExampleSymbolDefinitionType
    {
        Example,
        ExampleSearch,
    }

    public static class ExampleSymbolDefinitions
    {
        public static readonly IntermediateSymbolDefinition Example = new IntermediateSymbolDefinition(
            ExampleSymbolDefinitionType.Example.ToString(),
            new[]
            {
                new IntermediateFieldDefinition(nameof(ExampleSymbolFields.Value), IntermediateFieldType.String),
            },
            typeof(ExampleSymbol));

        public static readonly IntermediateSymbolDefinition ExampleSearch = new IntermediateSymbolDefinition(
            ExampleSymbolDefinitionType.ExampleSearch.ToString(),
            new[]
            {
                new IntermediateFieldDefinition(nameof(ExampleSearchSymbolFields.SearchFor), IntermediateFieldType.String),
            },
            typeof(ExampleSearchSymbol));

        static ExampleSymbolDefinitions()
        {
            ExampleSearch.AddTag(BurnConstants.BundleExtensionSearchSymbolDefinitionTag);
        }

        public static bool TryGetSymbolType(string name, out ExampleSymbolDefinitionType type)
        {
            return Enum.TryParse(name, out type);
        }

        public static IntermediateSymbolDefinition ByName(string name)
        {
            if (!TryGetSymbolType(name, out var type))
            {
                return null;
            }
            return ByType(type);
        }

        public static IntermediateSymbolDefinition ByType(ExampleSymbolDefinitionType type)
        {
            switch (type)
            {
                case ExampleSymbolDefinitionType.Example:
                    return ExampleSymbolDefinitions.Example;

                case ExampleSymbolDefinitionType.ExampleSearch:
                    return ExampleSymbolDefinitions.ExampleSearch;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type));
            }
        }
    }
}