aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/SimpleTupleDefinitionCreator.cs
blob: 257f028c1e6702b23dba75f1fc5927984640dc08 (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
// 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 WixToolset.Data
{
    using System.Collections.Generic;

    internal class SimpleTupleDefinitionCreator : ITupleDefinitionCreator
    {
        private Dictionary<string, IntermediateTupleDefinition> CustomDefinitionByName { get; } = new Dictionary<string, IntermediateTupleDefinition>();

        public void AddCustomTupleDefinition(IntermediateTupleDefinition definition)
        {
            if (!this.CustomDefinitionByName.TryGetValue(definition.Name, out var existing) || definition.Revision > existing.Revision)
            {
                this.CustomDefinitionByName[definition.Name] = definition;
            }
        }

        public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition)
        {
            tupleDefinition = TupleDefinitions.ByName(name);

            if (tupleDefinition == null)
            {
                tupleDefinition = this.CustomDefinitionByName.GetValueOrDefault(name);
            }

            return tupleDefinition != null;
        }
    }
}