Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Structures / CellConstant.cs / 3 / CellConstant.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Data.Common.Utils;
using System.Collections.Generic;
using System.Text;
using System.Data.Mapping.ViewGeneration.CqlGeneration;
using System.Diagnostics;
using System.Data.Metadata.Edm;
using System.Data.Mapping.ViewGeneration.Utils;
namespace System.Data.Mapping.ViewGeneration.Structures {
// This class denotes a constant that can be stored in multiconstants or
// projected in fields
internal class CellConstant : InternalBase {
protected CellConstant() {
// Private default constuctor so that no can construct this
// object externally other than via subclasses
}
#region Fields
// Two constants to denote nulls and undefined values
// Order is important -- it is guaranteed by C# (see Section 10.4.5.1)
internal static readonly IEqualityComparer EqualityComparer = new CellConstantComparer();
internal static readonly CellConstant Null = new CellConstant();
internal static readonly CellConstant Undefined = new CellConstant();
internal static readonly CellConstant NotNull = NegatedCellConstant.CreateNotNull();
//Represents scalar constants within a finite set that are not specified explicitly in the domain
// Currently only used as a Sentinel node to prevent expression optimization
internal static readonly CellConstant AllOtherConstants = new CellConstant();
#endregion
#region Methods
internal bool IsNull() {
return EqualityComparer.Equals(this, CellConstant.Null);
}
internal bool IsUndefined() {
return EqualityComparer.Equals(this, CellConstant.Undefined);
}
internal virtual bool IsNotNull() {
// Provide a default implementation and let the subclasses
// override it
return false; // NegatedCellConstant handles it
}
// effects: Returns true if this contains not null
internal virtual bool HasNotNull() {
// Provide a default implementation and let the subclasses
// override it
return false; // NegatedCellConstant handles it
}
// effects: Modifies builder to contain the appropriate expression
// corresponding to this. outputMember is the member to which this constant is directed.
// blockAlias is the alias for the SELECT FROM WHERE block where this constant is being projected
// if not null. Returns the modified stringbuilder
internal virtual StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias) {
// Constants will never be simply entity sets -- so we can use Property on the path
// constType is the type of this we need to cast to
EdmType constType = Helper.GetModelTypeUsage(outputMember.LastMember).EdmType;
Debug.Assert(this != Undefined && this != NotNull, "Generating Cql for undefined slots or not-nulls?");
Debug.Assert(this == Null, "Probably forgot to override this method in a subclass");
// need to cast
builder.Append("CAST(NULL AS ");
CqlWriter.AppendEscapedTypeName(builder, constType);
builder.Append(')');
return builder;
}
// effects: Returns true if right has the same contents as this
protected virtual int GetHash() {
Debug.Assert(this == Null || this == Undefined || this == AllOtherConstants,
"CellConstants can only be Null, Undefined, or AllOtherConstants");
return 0;
}
// effects: Returns true if right has the same contents as this
protected virtual bool IsEqualTo(CellConstant right) {
Debug.Assert(this == Null || this == Undefined || this == AllOtherConstants,
"CellConstants can only be Null, Undefined, or AllOtherConstants");
return this == right;
}
public override bool Equals(object obj)
{
CellConstant cellConst = obj as CellConstant;
if (cellConst == null)
{
return false;
}
else
{
return IsEqualTo(cellConst);
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
internal virtual string ToUserString() {
StringBuilder builder = new StringBuilder();
InternalToString(builder, false);
return builder.ToString();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static void ConstantsToUserString(StringBuilder builder, Set constants) {
bool isFirst = true;
foreach (CellConstant constant in constants) {
if (isFirst == false) {
builder.Append(System.Data.Entity.Strings.ViewGen_CommaBlank);
}
isFirst = false;
string constrStr = constant.ToUserString();
builder.Append(constrStr);
}
}
private void InternalToString(StringBuilder builder, bool isInvariant) {
string result;
if (this == Null) {
result = isInvariant ? "NULL" : System.Data.Entity.Strings.ViewGen_Null;
} else if (this == Undefined) {
Debug.Assert(isInvariant, "We should not emit a message about Undefined constants to the user");
result = "?";
} else if (this == NotNull) {
result = isInvariant? "NOT_NULL": System.Data.Entity.Strings.ViewGen_NotNull;
} else if (this == AllOtherConstants){
result = "AllOtherConstants";
} else {
Debug.Fail("No other constants handled by this class");
result = isInvariant? "FAILURE": System.Data.Entity.Strings.ViewGen_Failure;
}
builder.Append(result);
}
internal override void ToCompactString(StringBuilder builder) {
InternalToString(builder, true);
}
#endregion
#region Comparer class
private class CellConstantComparer : IEqualityComparer {
public bool Equals(CellConstant left, CellConstant right) {
// Quick check with references
if (object.ReferenceEquals(left, right)) {
// Gets the Null and Undefined case as well
return true;
}
// One of them is non-null at least. So if the other one is
// null, we cannot be equal
if (left == null || right == null) {
return false;
}
// Both are non-null at this point
return left.IsEqualTo(right);
}
public int GetHashCode(CellConstant key) {
EntityUtil.CheckArgumentNull(key, "key");
return key.GetHash();
}
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Data.Common.Utils;
using System.Collections.Generic;
using System.Text;
using System.Data.Mapping.ViewGeneration.CqlGeneration;
using System.Diagnostics;
using System.Data.Metadata.Edm;
using System.Data.Mapping.ViewGeneration.Utils;
namespace System.Data.Mapping.ViewGeneration.Structures {
// This class denotes a constant that can be stored in multiconstants or
// projected in fields
internal class CellConstant : InternalBase {
protected CellConstant() {
// Private default constuctor so that no can construct this
// object externally other than via subclasses
}
#region Fields
// Two constants to denote nulls and undefined values
// Order is important -- it is guaranteed by C# (see Section 10.4.5.1)
internal static readonly IEqualityComparer EqualityComparer = new CellConstantComparer();
internal static readonly CellConstant Null = new CellConstant();
internal static readonly CellConstant Undefined = new CellConstant();
internal static readonly CellConstant NotNull = NegatedCellConstant.CreateNotNull();
//Represents scalar constants within a finite set that are not specified explicitly in the domain
// Currently only used as a Sentinel node to prevent expression optimization
internal static readonly CellConstant AllOtherConstants = new CellConstant();
#endregion
#region Methods
internal bool IsNull() {
return EqualityComparer.Equals(this, CellConstant.Null);
}
internal bool IsUndefined() {
return EqualityComparer.Equals(this, CellConstant.Undefined);
}
internal virtual bool IsNotNull() {
// Provide a default implementation and let the subclasses
// override it
return false; // NegatedCellConstant handles it
}
// effects: Returns true if this contains not null
internal virtual bool HasNotNull() {
// Provide a default implementation and let the subclasses
// override it
return false; // NegatedCellConstant handles it
}
// effects: Modifies builder to contain the appropriate expression
// corresponding to this. outputMember is the member to which this constant is directed.
// blockAlias is the alias for the SELECT FROM WHERE block where this constant is being projected
// if not null. Returns the modified stringbuilder
internal virtual StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias) {
// Constants will never be simply entity sets -- so we can use Property on the path
// constType is the type of this we need to cast to
EdmType constType = Helper.GetModelTypeUsage(outputMember.LastMember).EdmType;
Debug.Assert(this != Undefined && this != NotNull, "Generating Cql for undefined slots or not-nulls?");
Debug.Assert(this == Null, "Probably forgot to override this method in a subclass");
// need to cast
builder.Append("CAST(NULL AS ");
CqlWriter.AppendEscapedTypeName(builder, constType);
builder.Append(')');
return builder;
}
// effects: Returns true if right has the same contents as this
protected virtual int GetHash() {
Debug.Assert(this == Null || this == Undefined || this == AllOtherConstants,
"CellConstants can only be Null, Undefined, or AllOtherConstants");
return 0;
}
// effects: Returns true if right has the same contents as this
protected virtual bool IsEqualTo(CellConstant right) {
Debug.Assert(this == Null || this == Undefined || this == AllOtherConstants,
"CellConstants can only be Null, Undefined, or AllOtherConstants");
return this == right;
}
public override bool Equals(object obj)
{
CellConstant cellConst = obj as CellConstant;
if (cellConst == null)
{
return false;
}
else
{
return IsEqualTo(cellConst);
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
internal virtual string ToUserString() {
StringBuilder builder = new StringBuilder();
InternalToString(builder, false);
return builder.ToString();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static void ConstantsToUserString(StringBuilder builder, Set constants) {
bool isFirst = true;
foreach (CellConstant constant in constants) {
if (isFirst == false) {
builder.Append(System.Data.Entity.Strings.ViewGen_CommaBlank);
}
isFirst = false;
string constrStr = constant.ToUserString();
builder.Append(constrStr);
}
}
private void InternalToString(StringBuilder builder, bool isInvariant) {
string result;
if (this == Null) {
result = isInvariant ? "NULL" : System.Data.Entity.Strings.ViewGen_Null;
} else if (this == Undefined) {
Debug.Assert(isInvariant, "We should not emit a message about Undefined constants to the user");
result = "?";
} else if (this == NotNull) {
result = isInvariant? "NOT_NULL": System.Data.Entity.Strings.ViewGen_NotNull;
} else if (this == AllOtherConstants){
result = "AllOtherConstants";
} else {
Debug.Fail("No other constants handled by this class");
result = isInvariant? "FAILURE": System.Data.Entity.Strings.ViewGen_Failure;
}
builder.Append(result);
}
internal override void ToCompactString(StringBuilder builder) {
InternalToString(builder, true);
}
#endregion
#region Comparer class
private class CellConstantComparer : IEqualityComparer {
public bool Equals(CellConstant left, CellConstant right) {
// Quick check with references
if (object.ReferenceEquals(left, right)) {
// Gets the Null and Undefined case as well
return true;
}
// One of them is non-null at least. So if the other one is
// null, we cannot be equal
if (left == null || right == null) {
return false;
}
// Both are non-null at this point
return left.IsEqualTo(right);
}
public int GetHashCode(CellConstant key) {
EntityUtil.CheckArgumentNull(key, "key");
return key.GetHash();
}
}
#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
- Triangle.cs
- Vector3DAnimationBase.cs
- AsynchronousChannelMergeEnumerator.cs
- VolatileResourceManager.cs
- QueueProcessor.cs
- XmlSchemaComplexContentRestriction.cs
- SimpleApplicationHost.cs
- TabControlDesigner.cs
- DynamicDocumentPaginator.cs
- CodeEntryPointMethod.cs
- DocumentOrderComparer.cs
- itemelement.cs
- RightsManagementEncryptionTransform.cs
- DesignerSerializationVisibilityAttribute.cs
- RelationalExpressions.cs
- UIElementParaClient.cs
- ServiceMetadataExtension.cs
- _NTAuthentication.cs
- ListControlActionList.cs
- RuleDefinitions.cs
- IEnumerable.cs
- ControlEvent.cs
- XmlSerializerSection.cs
- ChtmlPhoneCallAdapter.cs
- QuaternionValueSerializer.cs
- ProxyElement.cs
- ReadOnlyHierarchicalDataSource.cs
- DataGridViewCellPaintingEventArgs.cs
- CheckableControlBaseAdapter.cs
- PageTheme.cs
- PropertyEmitterBase.cs
- DependentTransaction.cs
- IIS7WorkerRequest.cs
- OracleColumn.cs
- OciLobLocator.cs
- SchemaDeclBase.cs
- LoginAutoFormat.cs
- AvTrace.cs
- SimpleType.cs
- TabItemWrapperAutomationPeer.cs
- MemoryFailPoint.cs
- OAVariantLib.cs
- XsltSettings.cs
- _HeaderInfoTable.cs
- XmlResolver.cs
- OdbcUtils.cs
- DataRowComparer.cs
- DateTimeValueSerializer.cs
- Parser.cs
- FieldTemplateUserControl.cs
- CopyAction.cs
- SaveFileDialog.cs
- XmlSchemaInclude.cs
- TypeDependencyAttribute.cs
- IriParsingElement.cs
- Timer.cs
- PathParser.cs
- Literal.cs
- Thread.cs
- HebrewNumber.cs
- UpdateRecord.cs
- ValuePatternIdentifiers.cs
- GridViewSelectEventArgs.cs
- Geometry.cs
- ConnectionsZoneDesigner.cs
- FontDialog.cs
- XmlSchemaGroupRef.cs
- ArraySortHelper.cs
- JapaneseLunisolarCalendar.cs
- DataBoundControlActionList.cs
- StatusBar.cs
- HwndHost.cs
- SingleStorage.cs
- TCPClient.cs
- SchemaNames.cs
- List.cs
- UserControl.cs
- PnrpPeerResolverBindingElement.cs
- Help.cs
- DataListItemEventArgs.cs
- PopupEventArgs.cs
- TableLayoutSettingsTypeConverter.cs
- MasterPageParser.cs
- OutputCacheProfile.cs
- GridViewRowPresenterBase.cs
- Vector3DConverter.cs
- ControllableStoryboardAction.cs
- Match.cs
- Rfc2898DeriveBytes.cs
- QuadraticBezierSegment.cs
- TripleDESCryptoServiceProvider.cs
- HashHelpers.cs
- ComponentRenameEvent.cs
- DataGridHelper.cs
- ItemsControlAutomationPeer.cs
- WindowInteractionStateTracker.cs
- TypeExtensionSerializer.cs
- CodeCatchClause.cs
- UIAgentMonitor.cs
- HttpCapabilitiesSectionHandler.cs