aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/Symbol.cs
blob: 8bcdd4f0a2a9ebb45938bfc6b1129c02d2f52d5e (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// Symbol representing a single row in a database.
    /// </summary>
    public sealed class Symbol
    {
        private HashSet<Symbol> possibleConflictSymbols;
        private HashSet<Symbol> redundantSymbols;

        /// <summary>
        /// Creates a symbol for a row.
        /// </summary>
        /// <param name="row">Row for the symbol</param>
        public Symbol(IntermediateSection section, IntermediateTuple tuple)
        {
            this.Row = tuple;
            this.Section = section;
            this.Name = String.Concat(this.Row.Definition.Name, ":", this.Row.Id.Id);
        }

        /// <summary>
        /// Gets the accessibility of the symbol which is a direct reflection of the accessibility of the row's accessibility.
        /// </summary>
        /// <value>Accessbility of the symbol.</value>
        public AccessModifier Access => this.Row.Id.Access;

        /// <summary>
        /// Gets the name of the symbol.
        /// </summary>
        /// <value>Name of the symbol.</value>
        public string Name { get; }

        /// <summary>
        /// Gets the row for this symbol.
        /// </summary>
        /// <value>Row for this symbol.</value>
        public IntermediateTuple Row { get; }

        /// <summary>
        /// Gets the section for the symbol.
        /// </summary>
        /// <value>Section for the symbol.</value>
        public IntermediateSection Section { get; }

        /// <summary>
        /// Gets any duplicates of this symbol that are possible conflicts.
        /// </summary>
        public IEnumerable<Symbol> PossiblyConflictingSymbols { get { return this.possibleConflictSymbols ?? Enumerable.Empty<Symbol>(); } }

        /// <summary>
        /// Gets any duplicates of this symbol that are redundant.
        /// </summary>
        public IEnumerable<Symbol> RedundantSymbols { get { return this.redundantSymbols ?? Enumerable.Empty<Symbol>(); } }

        /// <summary>
        /// Adds a duplicate symbol that is a possible conflict.
        /// </summary>
        /// <param name="symbol">Symbol that is a possible conflict of this symbol.</param>
        public void AddPossibleConflict(Symbol symbol)
        {
            if (null == this.possibleConflictSymbols)
            {
                this.possibleConflictSymbols = new HashSet<Symbol>();
            }

            this.possibleConflictSymbols.Add(symbol);
        }

        /// <summary>
        /// Adds a duplicate symbol that is redundant.
        /// </summary>
        /// <param name="symbol">Symbol that is redundant of this symbol.</param>
        public void AddRedundant(Symbol symbol)
        {
            if (null == this.redundantSymbols)
            {
                this.redundantSymbols = new HashSet<Symbol>();
            }

            this.redundantSymbols.Add(symbol);
        }
    }
}