Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity / System / Data / SqlClient / SqlGen / SymbolUsageManager.cs
blob7f9152076a69ac95ef28a27c864b77877e744b52
1 //---------------------------------------------------------------------
2 // <copyright file="SymbolUsageManager.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 //---------------------------------------------------------------------
9 using System;
10 using System.Collections.Generic;
12 namespace System.Data.SqlClient.SqlGen
14 /// <summary>
15 /// Used for wrapping a boolean value as an object.
16 /// </summary>
17 internal class BoolWrapper
19 internal bool Value {get; set;}
21 internal BoolWrapper()
23 this.Value = false;
27 /// <summary>
28 /// Tracks the usage of symbols.
29 /// When registering a symbol with the usage manager if an input symbol is specified,
30 /// than the usage of the two is 'connected' - if one ever gets marked as used,
31 /// the other one becomes 'used' too.
32 /// </summary>
33 internal class SymbolUsageManager
35 private readonly Dictionary<Symbol, BoolWrapper> optionalColumnUsage = new Dictionary<Symbol, BoolWrapper>();
37 internal bool ContainsKey(Symbol key)
39 return optionalColumnUsage.ContainsKey(key);
42 internal bool TryGetValue(Symbol key, out bool value)
44 BoolWrapper wrapper;
45 if (optionalColumnUsage.TryGetValue(key, out wrapper))
47 value = wrapper.Value;
48 return true;
51 value = false;
52 return false;
55 internal void Add(Symbol sourceSymbol, Symbol symbolToAdd)
57 BoolWrapper wrapper;
58 if (sourceSymbol == null || !this.optionalColumnUsage.TryGetValue(sourceSymbol, out wrapper))
60 wrapper = new BoolWrapper();
62 this.optionalColumnUsage.Add(symbolToAdd, wrapper);
65 internal void MarkAsUsed(Symbol key)
67 if (optionalColumnUsage.ContainsKey(key))
69 optionalColumnUsage[key].Value = true;
73 internal bool IsUsed(Symbol key)
75 return optionalColumnUsage[key].Value;