//--------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- namespace System.Data.Mapping.ViewGeneration.Validation { using System.Collections.Generic; using System.Data.Common.CommandTrees; using System.Data.Common.Utils; using System.Data.Mapping.ViewGeneration.Structures; using System.Diagnostics; using System.Text; /// /// Represents a slot that is projected by C and S queries in a cell. /// internal class ViewCellSlot : ProjectedSlot { #region Constructor // effects: /// /// Creates a view cell slot that corresponds to in some cell. The and represent the /// slots in the left and right queries of the view cell. /// internal ViewCellSlot(int slotNum, MemberProjectedSlot cSlot, MemberProjectedSlot sSlot) { m_slotNum = slotNum; m_cSlot = cSlot; m_sSlot = sSlot; } #endregion #region Fields private readonly int m_slotNum; private readonly MemberProjectedSlot m_cSlot; private readonly MemberProjectedSlot m_sSlot; #endregion #region Properties /// /// Returns the slot corresponding to the left cellquery. /// internal MemberProjectedSlot CSlot { get { return m_cSlot; } } /// /// Returns the slot corresponding to the right cellquery. /// internal MemberProjectedSlot SSlot { get { return m_sSlot; } } #endregion #region Comparer/String Methods protected override bool IsEqualTo(ProjectedSlot right) { ViewCellSlot rightSlot = right as ViewCellSlot; if (rightSlot == null) { return false; } return m_slotNum == rightSlot.m_slotNum && MemberProjectedSlot.EqualityComparer.Equals(m_cSlot, rightSlot.m_cSlot) && MemberProjectedSlot.EqualityComparer.Equals(m_sSlot, rightSlot.m_sSlot); } protected override int GetHash() { return MemberProjectedSlot.EqualityComparer.GetHashCode(m_cSlot) ^ MemberProjectedSlot.EqualityComparer.GetHashCode(m_sSlot) ^ m_slotNum; } /// /// Given a list of , converts the left/right slots (if left is true/false) to a human-readable string. /// internal static string SlotsToUserString(IEnumerable slots, bool isFromCside) { StringBuilder builder = new StringBuilder(); bool first = true; foreach (ViewCellSlot slot in slots) { if (false == first) { builder.Append(", "); } builder.Append(SlotToUserString(slot, isFromCside)); first = false; } return builder.ToString(); } internal static string SlotToUserString(ViewCellSlot slot, bool isFromCside) { MemberProjectedSlot actualSlot = isFromCside ? slot.CSlot : slot.SSlot; string result = StringUtil.FormatInvariant("{0}", actualSlot); return result; } /// /// Not supported in this class. /// internal override string GetCqlFieldAlias(MemberPath outputMember) { Debug.Fail("Should not be called."); return null; // To keep the compiler happy } /// /// Not supported in this class. /// internal override StringBuilder AsEsql(StringBuilder builder, MemberPath outputMember, string blockAlias, int indentLevel) { Debug.Fail("Should not be called."); return null; // To keep the compiler happy } /// /// Not supported in this class. /// internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember) { Debug.Fail("Should not be called."); return null; } internal override void ToCompactString(StringBuilder builder) { builder.Append('<'); StringUtil.FormatStringBuilder(builder, "{0}", m_slotNum); builder.Append(':'); m_cSlot.ToCompactString(builder); builder.Append('-'); m_sSlot.ToCompactString(builder); builder.Append('>'); } #endregion } }