aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/SimpleTupleDefinitionCreator.cs
blob: e22d53e7453d0079074a6fcb63106e5e31cd1ed8 (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 SimpleSymbolDefinitionCreator : ISymbolDefinitionCreator
    {
        private Dictionary<string, IntermediateSymbolDefinition> CustomDefinitionByName { get; } = new Dictionary<string, IntermediateSymbolDefinition>();

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

        public bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
        {
            symbolDefinition = SymbolDefinitions.ByName(name);

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

            return symbolDefinition != null;
        }
    }
}