Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Mapping / ViewGeneration / Validation / ViewCellSlot.cs
1 //---------------------------------------------------------------------
2 // <copyright file="ViewCellSlot.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 namespace System.Data.Mapping.ViewGeneration.Validation
11 {
12     using System.Collections.Generic;
13     using System.Data.Common.CommandTrees;
14     using System.Data.Common.Utils;
15     using System.Data.Mapping.ViewGeneration.Structures;
16     using System.Diagnostics;
17     using System.Text;
18
19     /// <summary>
20     /// Represents a slot that is projected by C and S queries in a cell.
21     /// </summary>
22     internal class ViewCellSlot : ProjectedSlot
23     {
24         #region Constructor
25         // effects: 
26         /// <summary>
27         /// Creates a view cell slot that corresponds to <paramref name="slotNum"/> in some cell. The <paramref name="cSlot"/> and <paramref name="sSlot"/> represent the
28         /// slots in the left and right queries of the view cell.
29         /// </summary>
30         internal ViewCellSlot(int slotNum, MemberProjectedSlot cSlot, MemberProjectedSlot sSlot)
31         {
32             m_slotNum = slotNum;
33             m_cSlot = cSlot;
34             m_sSlot = sSlot;
35         }
36         #endregion
37
38         #region Fields
39         private readonly int m_slotNum;
40         private readonly MemberProjectedSlot m_cSlot;
41         private readonly MemberProjectedSlot m_sSlot;
42         #endregion
43
44         #region Properties
45         /// <summary>
46         /// Returns the slot corresponding to the left cellquery.
47         /// </summary>
48         internal MemberProjectedSlot CSlot
49         {
50             get { return m_cSlot; }
51         }
52
53         /// <summary>
54         /// Returns the slot corresponding to the right cellquery.
55         /// </summary>
56         internal MemberProjectedSlot SSlot
57         {
58             get { return m_sSlot; }
59         }
60         #endregion
61
62         #region Comparer/String Methods
63         protected override bool IsEqualTo(ProjectedSlot right)
64         {
65             ViewCellSlot rightSlot = right as ViewCellSlot;
66             if (rightSlot == null)
67             {
68                 return false;
69             }
70
71             return m_slotNum == rightSlot.m_slotNum &&
72                 MemberProjectedSlot.EqualityComparer.Equals(m_cSlot, rightSlot.m_cSlot) &&
73                 MemberProjectedSlot.EqualityComparer.Equals(m_sSlot, rightSlot.m_sSlot);
74         }
75
76         protected override int GetHash()
77         {
78             return MemberProjectedSlot.EqualityComparer.GetHashCode(m_cSlot) ^
79                    MemberProjectedSlot.EqualityComparer.GetHashCode(m_sSlot) ^
80                    m_slotNum;
81         }
82
83         /// <summary>
84         /// Given a list of <paramref name="slots"/>, converts the left/right slots (if left is true/false) to a human-readable string.
85         /// </summary>
86         internal static string SlotsToUserString(IEnumerable<ViewCellSlot> slots, bool isFromCside)
87         {
88             StringBuilder builder = new StringBuilder();
89             bool first = true;
90             foreach (ViewCellSlot slot in slots)
91             {
92                 if (false == first)
93                 {
94                     builder.Append(", ");
95                 }
96                 builder.Append(SlotToUserString(slot, isFromCside));
97                 first = false;
98             }
99             return builder.ToString();
100         }
101
102         internal static string SlotToUserString(ViewCellSlot slot, bool isFromCside)
103         {
104             MemberProjectedSlot actualSlot = isFromCside ? slot.CSlot : slot.SSlot;
105             string result = StringUtil.FormatInvariant("{0}", actualSlot);
106             return result;
107         }
108
109         /// <summary>
110         /// Not supported in this class.
111         /// </summary>
112         internal override string GetCqlFieldAlias(MemberPath outputMember)
113         {
114             Debug.Fail("Should not be called.");
115             return null; // To keep the compiler happy
116         }
117
118         /// <summary>
119         /// Not supported in this class.
120         /// </summary>
121         internal override StringBuilder AsEsql(StringBuilder builder, MemberPath outputMember, string blockAlias, int indentLevel)
122         {
123             Debug.Fail("Should not be called.");
124             return null; // To keep the compiler happy
125         }
126
127         /// <summary>
128         /// Not supported in this class.
129         /// </summary>
130         internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
131         {
132             Debug.Fail("Should not be called.");
133             return null;
134         }
135
136         internal override void ToCompactString(StringBuilder builder)
137         {
138             builder.Append('<');
139             StringUtil.FormatStringBuilder(builder, "{0}", m_slotNum);
140             builder.Append(':');
141             m_cSlot.ToCompactString(builder);
142             builder.Append('-');
143             m_sSlot.ToCompactString(builder);
144             builder.Append('>');
145         }
146         #endregion
147     }
148 }