Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity / System / Data / SqlClient / SqlGen / OptionalColumn.cs
blob9670a2365eabf09060eea4348817471baade5d47
1 //---------------------------------------------------------------------
2 // <copyright file="OptionalColumn.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;
11 using System.Diagnostics;
13 namespace System.Data.SqlClient.SqlGen
15 /// <summary>
16 /// Represents a column in a select list that should be printed only if it is later used.
17 /// Such columns get added by <see cref="SqlGenerator.AddDefaultColumns"/>.
18 /// The SymbolUsageManager associated with the OptionalColumn has the information whether the column
19 /// has been used based on its symbol.
20 /// </summary>
21 internal sealed class OptionalColumn
23 #region Private State
24 private readonly SymbolUsageManager m_usageManager;
26 // The SqlBuilder that contains the column building blocks (e.g: "c.X as X1")
27 private readonly SqlBuilder m_builder = new SqlBuilder();
29 // The symbol representing the optional column
30 private readonly Symbol m_symbol;
31 #endregion
33 #region Internal Methods
34 /// <summary>
35 /// Append to the "fragment" representing this column
36 /// </summary>
37 internal void Append(object s)
39 m_builder.Append(s);
42 internal void MarkAsUsed()
44 this.m_usageManager.MarkAsUsed(this.m_symbol);
46 #endregion
48 #region Constructor
49 internal OptionalColumn(SymbolUsageManager usageManager, Symbol symbol)
51 this.m_usageManager = usageManager;
52 this.m_symbol = symbol;
54 #endregion
56 #region Internal members
58 /// <summary>
59 /// Writes that fragment that represents the optional column
60 /// if the usage manager says it is used.
61 /// </summary>
62 /// <param name="writer"></param>
63 /// <param name="sqlGenerator"></param>
64 public bool WriteSqlIfUsed(SqlWriter writer, SqlGenerator sqlGenerator, string separator)
66 if (m_usageManager.IsUsed(m_symbol))
68 writer.Write(separator);
69 m_builder.WriteSql(writer, sqlGenerator);
70 return true;
72 return false;
74 #endregion