Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Structures / TypeRestriction.cs / 1305376 / TypeRestriction.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Data.Common.Utils;
using System.Data.Common.Utils.Boolean;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Data.Mapping.ViewGeneration.CqlGeneration;
using System.Data.Metadata.Edm;
namespace System.Data.Mapping.ViewGeneration.Structures
{
using DomainBoolExpr = BoolExpr>;
using CellConstantSet = Set;
// A class that denotes the boolean expression: "varType in values"
// See the comments in OneOfConst for partially and fully-done objects
internal class TypeRestriction : MemberRestriction
{
#region Constructors
// effects: Creates a partial OneOfTypeConst of the form "node in values"
internal TypeRestriction(MemberPath node, IEnumerable values)
: base(new MemberProjectedSlot(node), CreateTypeConstants(values)) { }
// effects: Creates a partial OneOfTypeConst of the form "node = values"
internal TypeRestriction(MemberPath node, Constant value) :
base(new MemberProjectedSlot(node), value)
{
Debug.Assert(value is TypeConstant || value.IsNull(), "Type or NULL expected");
}
// effects: Creates an expression of the form "type of node in type constants
// corresponding to values", i.e., a boolean expression of the form "TypeOf(slot) in values"
// possibleValues are all the values that node's type can take
internal TypeRestriction(MemberPath node, IEnumerable values,
IEnumerable possibleValues)
: base(new MemberProjectedSlot(node), CreateTypeConstants(values), CreateTypeConstants(possibleValues)) { }
// effects: Creates a "fully-done" OneOfTypeConst that represents
// "node in values". possibleValues are all the values that node's type can take
internal TypeRestriction(MemberPath node, IEnumerable values,
IEnumerable possibleValues)
: base(new MemberProjectedSlot(node), values, possibleValues) { }
// effects: Creates an expression of the form "slot = value"
// possibleValues are all the values that slot can take
internal TypeRestriction(MemberPath node, Constant value, IEnumerable possibleValues) :
base(new MemberProjectedSlot(node), value, possibleValues)
{
Debug.Assert(value is TypeConstant || value.IsNull(), "Type or NULL expected");
}
// effects: Creates an expression of the form "slot in domain"
internal TypeRestriction(MemberProjectedSlot slot, Domain domain)
: base(slot, domain)
{
}
#endregion
#region Helper static methods
// effects: Given a list of types (which can contain nulls),
// returns a corresponding list of Type Constants for those types
private static IEnumerable CreateTypeConstants(IEnumerable types)
{
foreach (EdmType type in types)
{
if (type == null)
{
yield return Constant.Null;
}
else
{
yield return new TypeConstant(type);
}
}
}
#endregion
#region Methods
// requires: IsFullyDone is true
// effects: Fixes the range of this in accordance with range
internal override DomainBoolExpr FixRange(Set range, MemberDomainMap memberDomainMap)
{
Debug.Assert(IsFullyDone, "Ranges are fixed only for fully done OneOfConsts");
IEnumerable possibleValues = memberDomainMap.GetDomain(RestrictedMemberSlot.MemberPath);
BoolLiteral newLiteral = new TypeRestriction(RestrictedMemberSlot, new Domain(range, possibleValues));
return newLiteral.GetDomainBoolExpression(memberDomainMap);
}
internal override StringBuilder AsCql(StringBuilder builder, string blockAlias, bool canSkipIsNotNull)
{
// type comparison: make a big OR
// Important to enclose all the OR statements in () !
if (Domain.Count > 1)
{
builder.Append('(');
}
bool isFirst = true;
// Add Cql of the form "(T.A IS OF (ONLY Person) OR .....)"
foreach (Constant constant in Domain.Values)
{
TypeConstant typeConstant = constant as TypeConstant;
Debug.Assert(typeConstant != null || constant.IsNull(), "Constants for type checks must be type constants or NULLs");
if (isFirst == false)
{
builder.Append(" OR ");
}
isFirst = false;
if (RestrictedMemberSlot.MemberPath.EdmType is RefType)
{
builder.Append("Deref(");
RestrictedMemberSlot.MemberPath.AsCql(builder, blockAlias);
builder.Append(')');
}
else
{
// non-reference type
RestrictedMemberSlot.MemberPath.AsCql(builder, blockAlias);
}
if (constant.IsNull())
{
builder.Append(" IS NULL");
}
else
{
// type constant
builder.Append(" IS OF (ONLY ");
CqlWriter.AppendEscapedTypeName(builder, typeConstant.CdmType);
builder.Append(')');
}
}
if (Domain.Count > 1)
{
builder.Append(')');
}
return builder;
}
internal override StringBuilder AsUserString(StringBuilder builder, string blockAlias, bool canSkipIsNotNull)
{
// Add user readable string of the form "(T.A IS OF (ONLY Person) OR .....)"
if (RestrictedMemberSlot.MemberPath.EdmType is RefType)
{
builder.Append("Deref(");
RestrictedMemberSlot.MemberPath.AsCql(builder, blockAlias);
builder.Append(')');
}
else
{
// non-reference type
RestrictedMemberSlot.MemberPath.AsCql(builder, blockAlias);
}
if (Domain.Count > 1)
{
builder.Append(" is a (");
}
else
{
builder.Append(" is type ");
}
bool isFirst = true;
foreach (Constant constant in Domain.Values)
{
TypeConstant typeConstant = constant as TypeConstant;
Debug.Assert(typeConstant != null || constant.IsNull(), "Constants for type checks must be type constants or NULLs");
if (isFirst == false)
{
builder.Append(" OR ");
}
if (constant.IsNull())
{
builder.Append(" NULL");
}
else
{
CqlWriter.AppendEscapedTypeName(builder, typeConstant.CdmType);
}
isFirst = false;
}
if (Domain.Count > 1)
{
builder.Append(')');
}
return builder;
}
#endregion
#region String methods
internal override void ToCompactString(StringBuilder builder)
{
builder.Append("type(");
RestrictedMemberSlot.ToCompactString(builder);
builder.Append(") IN (");
StringUtil.ToCommaSeparatedStringSorted(builder, Domain.Values);
builder.Append(")");
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PageAsyncTaskManager.cs
- JavascriptCallbackResponseProperty.cs
- BinHexEncoder.cs
- XamlVector3DCollectionSerializer.cs
- DateTimeUtil.cs
- BlockCollection.cs
- InkCanvas.cs
- DataTableMapping.cs
- SqlUserDefinedAggregateAttribute.cs
- SizeLimitedCache.cs
- FlowDocumentPaginator.cs
- BCryptNative.cs
- CollaborationHelperFunctions.cs
- TextElementEditingBehaviorAttribute.cs
- CompositeFontParser.cs
- TextProviderWrapper.cs
- DataSourceCache.cs
- UInt32Storage.cs
- DiscardableAttribute.cs
- GridViewRow.cs
- Transform3DGroup.cs
- unitconverter.cs
- EntityCollection.cs
- RSAOAEPKeyExchangeDeformatter.cs
- LoadRetryHandler.cs
- Claim.cs
- StreamInfo.cs
- Vector3DCollectionValueSerializer.cs
- QilName.cs
- CodeTypeParameterCollection.cs
- ListBoxItemWrapperAutomationPeer.cs
- RegexMatchCollection.cs
- WSSecurityTokenSerializer.cs
- DrawListViewItemEventArgs.cs
- XmlSchemaFacet.cs
- SiteMembershipCondition.cs
- UserInitiatedNavigationPermission.cs
- WmlCalendarAdapter.cs
- ChangeConflicts.cs
- DetailsViewUpdatedEventArgs.cs
- DoubleAnimationUsingPath.cs
- TemplateBaseAction.cs
- CreateUserWizard.cs
- OneOfConst.cs
- IsolatedStorageFilePermission.cs
- SqlFacetAttribute.cs
- safemediahandle.cs
- TransactionProxy.cs
- FieldNameLookup.cs
- TextElement.cs
- EndpointAddressProcessor.cs
- _SSPIWrapper.cs
- ChunkedMemoryStream.cs
- CLRBindingWorker.cs
- MessageLogger.cs
- MultiBindingExpression.cs
- Rijndael.cs
- FlowDocumentReaderAutomationPeer.cs
- CustomErrorCollection.cs
- Point3DKeyFrameCollection.cs
- CriticalFinalizerObject.cs
- TextElementCollectionHelper.cs
- FontStyle.cs
- DataException.cs
- ServiceHostFactory.cs
- ScrollBarAutomationPeer.cs
- Registry.cs
- ListItemCollection.cs
- ComponentGlyph.cs
- DataTableReaderListener.cs
- SqlConnectionHelper.cs
- UInt16Converter.cs
- XmlSerializerFactory.cs
- IPAddressCollection.cs
- Graph.cs
- ByteStorage.cs
- PasswordBox.cs
- TableLayoutRowStyleCollection.cs
- Brush.cs
- DataGridViewCellStateChangedEventArgs.cs
- DeclaredTypeElementCollection.cs
- CustomError.cs
- CallbackValidatorAttribute.cs
- IntellisenseTextBox.designer.cs
- Events.cs
- SharedStatics.cs
- ExceptionHandlerDesigner.cs
- ActiveXMessageFormatter.cs
- SqlConnectionStringBuilder.cs
- MessagingActivityHelper.cs
- SingleSelectRootGridEntry.cs
- MonitoringDescriptionAttribute.cs
- PeerContact.cs
- HtmlProps.cs
- ResizeGrip.cs
- FilterException.cs
- ToolStripDropDownDesigner.cs
- ParseElementCollection.cs
- ElementHostPropertyMap.cs
- errorpatternmatcher.cs