1 //---------------------------------------------------------------------
2 // <copyright file="ViewCellSlot.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 namespace System.Data.Mapping.ViewGeneration.Validation
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;
20 /// Represents a slot that is projected by C and S queries in a cell.
22 internal class ViewCellSlot : ProjectedSlot
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.
30 internal ViewCellSlot(int slotNum, MemberProjectedSlot cSlot, MemberProjectedSlot sSlot)
39 private readonly int m_slotNum;
40 private readonly MemberProjectedSlot m_cSlot;
41 private readonly MemberProjectedSlot m_sSlot;
46 /// Returns the slot corresponding to the left cellquery.
48 internal MemberProjectedSlot CSlot
50 get { return m_cSlot; }
54 /// Returns the slot corresponding to the right cellquery.
56 internal MemberProjectedSlot SSlot
58 get { return m_sSlot; }
62 #region Comparer/String Methods
63 protected override bool IsEqualTo(ProjectedSlot right)
65 ViewCellSlot rightSlot = right as ViewCellSlot;
66 if (rightSlot == null)
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);
76 protected override int GetHash()
78 return MemberProjectedSlot.EqualityComparer.GetHashCode(m_cSlot) ^
79 MemberProjectedSlot.EqualityComparer.GetHashCode(m_sSlot) ^
84 /// Given a list of <paramref name="slots"/>, converts the left/right slots (if left is true/false) to a human-readable string.
86 internal static string SlotsToUserString(IEnumerable<ViewCellSlot> slots, bool isFromCside)
88 StringBuilder builder = new StringBuilder();
90 foreach (ViewCellSlot slot in slots)
96 builder.Append(SlotToUserString(slot, isFromCside));
99 return builder.ToString();
102 internal static string SlotToUserString(ViewCellSlot slot, bool isFromCside)
104 MemberProjectedSlot actualSlot = isFromCside ? slot.CSlot : slot.SSlot;
105 string result = StringUtil.FormatInvariant("{0}", actualSlot);
110 /// Not supported in this class.
112 internal override string GetCqlFieldAlias(MemberPath outputMember)
114 Debug.Fail("Should not be called.");
115 return null; // To keep the compiler happy
119 /// Not supported in this class.
121 internal override StringBuilder AsEsql(StringBuilder builder, MemberPath outputMember, string blockAlias, int indentLevel)
123 Debug.Fail("Should not be called.");
124 return null; // To keep the compiler happy
128 /// Not supported in this class.
130 internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
132 Debug.Fail("Should not be called.");
136 internal override void ToCompactString(StringBuilder builder)
139 StringUtil.FormatStringBuilder(builder, "{0}", m_slotNum);
141 m_cSlot.ToCompactString(builder);
143 m_sSlot.ToCompactString(builder);