aboutsummaryrefslogtreecommitdiff
path: root/src/test/Example.Extension/ExampleTupleDefinitions.cs
blob: 446c2c4552748e6685459f1036891ca2fb676106 (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 ExampleTupleDefinitionType
    {
        Example,
        ExampleSearch,
    }

    public static class ExampleTupleDefinitions
    {
        public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition(
            ExampleTupleDefinitionType.Example.ToString(),
            new[]
            {
                new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String),
            },
            typeof(ExampleTuple));

        public static readonly IntermediateTupleDefinition ExampleSearch = new IntermediateTupleDefinition(
            ExampleTupleDefinitionType.ExampleSearch.ToString(),
            new[]
            {
                new IntermediateFieldDefinition(nameof(ExampleSearchTupleFields.SearchFor), IntermediateFieldType.String),
            },
            typeof(ExampleSearchTuple));

        static ExampleTupleDefinitions()
        {
            ExampleSearch.AddTag(BurnConstants.BundleExtensionSearchTupleDefinitionTag);
        }

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

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

        public static IntermediateTupleDefinition ByType(ExampleTupleDefinitionType type)
        {
            switch (type)
            {
                case ExampleTupleDefinitionType.Example:
                    return ExampleTupleDefinitions.Example;

                case ExampleTupleDefinitionType.ExampleSearch:
                    return ExampleTupleDefinitions.ExampleSearch;

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