1
//---------------------------------------------------------------------
2 // <copyright file="SymbolUsageManager.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //---------------------------------------------------------------------
10 using System
.Collections
.Generic
;
12 namespace System
.Data
.SqlClient
.SqlGen
15 /// Used for wrapping a boolean value as an object.
17 internal class BoolWrapper
19 internal bool Value {get; set;}
21 internal BoolWrapper()
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.
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)
45 if (optionalColumnUsage
.TryGetValue(key
, out wrapper
))
47 value = wrapper
.Value
;
55 internal void Add(Symbol sourceSymbol
, Symbol symbolToAdd
)
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
;