| 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 WixToolset.Data |
| 4 | { |
| 5 | using System.Collections.Generic; |
| 6 | |
| 7 | internal class SimpleSymbolDefinitionCreator : ISymbolDefinitionCreator |
| 8 | { |
| 9 | private Dictionary<string, IntermediateSymbolDefinition> CustomDefinitionByName { get; } = new Dictionary<string, IntermediateSymbolDefinition>(); |
| 10 | |
| 11 | public void AddCustomSymbolDefinition(IntermediateSymbolDefinition definition) |
| 12 | { |
| 13 | if (!this.CustomDefinitionByName.TryGetValue(definition.Name, out var existing) || definition.Revision > existing.Revision) |
| 14 | { |
| 15 | this.CustomDefinitionByName[definition.Name] = definition; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition) |
| 20 | { |
| 21 | symbolDefinition = SymbolDefinitions.ByName(name); |
| 22 | |
| 23 | if (symbolDefinition == null) |
| 24 | { |
| 25 | symbolDefinition = this.CustomDefinitionByName.GetValueOrDefault(name); |
| 26 | } |
| 27 | |
| 28 | return symbolDefinition != null; |
| 29 | } |
| 30 | } |
| 31 | } |