Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Structures / ScalarConstant.cs / 1 / ScalarConstant.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Text; using System.Data.Common.Utils; using System.Data.Mapping.ViewGeneration.CqlGeneration; using System.Data.Mapping.ViewGeneration.Utils; using System.Data.Metadata.Edm; namespace System.Data.Mapping.ViewGeneration.Structures { // A class that denotes a constant value that can be stored in a // multiconstant or in a projected slot of a cellquery internal class ScalarConstant : CellConstant { #region Constructor // effects: Creates a scalar constant corresponding to value internal ScalarConstant(object value) { m_scalar = value; } #endregion #region Fields private object m_scalar; // The actual value of the scalar #endregion #region Properties internal object Value { get { return m_scalar;} } #endregion #region Methods // effects: See CellConstant.AsCql internal override StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias) { // A constant path better be more than just the extent EdmType constType = Helper.GetModelTypeUsage(outputMember.LastMember).EdmType; // Some built-in constants if (BuiltInTypeKind.PrimitiveType == constType.BuiltInTypeKind) { PrimitiveTypeKind primitiveTypeKind = ((PrimitiveType)constType).PrimitiveTypeKind; if (primitiveTypeKind == PrimitiveTypeKind.Boolean) { // This better be a boolean. Else we crash! bool val = (bool)m_scalar; string value = StringUtil.FormatInvariant("{0}", val); builder.Append(value); return builder; } else if (primitiveTypeKind == PrimitiveTypeKind.String) { // It's a string: no need to cast AppendEscapedScalar(builder); return builder; } } else if (BuiltInTypeKind.EnumType == constType.BuiltInTypeKind) { // Enumerated type - we should be able to cast it EnumMember enumValue = (EnumMember) m_scalar; builder.Append(enumValue.Name); return builder; } // Need to cast builder.Append("CAST("); AppendEscapedScalar(builder); builder.Append(" AS "); CqlWriter.AppendEscapedTypeName(builder, constType); builder.Append(')'); return builder; } // effects: Modifies builder to contain an escaped version of this private StringBuilder AppendEscapedScalar(StringBuilder builder) { string value = StringUtil.FormatInvariant("{0}", m_scalar); if (value.Contains("'")) { // Deal with strings with ' by doubling it value = value.Replace("'", "''"); } StringUtil.FormatStringBuilder(builder, "'{0}'", value); return builder; } // Returns true if this is semantically equivalent to obj protected override bool IsEqualTo(CellConstant right) { ScalarConstant rightScalarConstant = right as ScalarConstant; if (rightScalarConstant == null) { return false; } return CdpEqualityComparer.DefaultEqualityComparer.Equals(m_scalar, rightScalarConstant.m_scalar); } protected override int GetHash() { if (m_scalar == null) { return 1; } else { return m_scalar.GetHashCode(); } } private void InternalToString(StringBuilder builder, bool isInvariant) { EnumMember enumMember = m_scalar as EnumMember; if (enumMember != null) { builder.Append(enumMember.Name); } else if (m_scalar == null) { builder.Append(isInvariant? "NULL": System.Data.Entity.Strings.ViewGen_Null); } else { builder.Append(StringUtil.FormatInvariant("'{0}'", m_scalar)); } } internal override string ToUserString() { StringBuilder builder = new StringBuilder(); InternalToString(builder, false); return builder.ToString(); } internal override void ToCompactString(StringBuilder builder) { InternalToString(builder, true); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Text; using System.Data.Common.Utils; using System.Data.Mapping.ViewGeneration.CqlGeneration; using System.Data.Mapping.ViewGeneration.Utils; using System.Data.Metadata.Edm; namespace System.Data.Mapping.ViewGeneration.Structures { // A class that denotes a constant value that can be stored in a // multiconstant or in a projected slot of a cellquery internal class ScalarConstant : CellConstant { #region Constructor // effects: Creates a scalar constant corresponding to value internal ScalarConstant(object value) { m_scalar = value; } #endregion #region Fields private object m_scalar; // The actual value of the scalar #endregion #region Properties internal object Value { get { return m_scalar;} } #endregion #region Methods // effects: See CellConstant.AsCql internal override StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias) { // A constant path better be more than just the extent EdmType constType = Helper.GetModelTypeUsage(outputMember.LastMember).EdmType; // Some built-in constants if (BuiltInTypeKind.PrimitiveType == constType.BuiltInTypeKind) { PrimitiveTypeKind primitiveTypeKind = ((PrimitiveType)constType).PrimitiveTypeKind; if (primitiveTypeKind == PrimitiveTypeKind.Boolean) { // This better be a boolean. Else we crash! bool val = (bool)m_scalar; string value = StringUtil.FormatInvariant("{0}", val); builder.Append(value); return builder; } else if (primitiveTypeKind == PrimitiveTypeKind.String) { // It's a string: no need to cast AppendEscapedScalar(builder); return builder; } } else if (BuiltInTypeKind.EnumType == constType.BuiltInTypeKind) { // Enumerated type - we should be able to cast it EnumMember enumValue = (EnumMember) m_scalar; builder.Append(enumValue.Name); return builder; } // Need to cast builder.Append("CAST("); AppendEscapedScalar(builder); builder.Append(" AS "); CqlWriter.AppendEscapedTypeName(builder, constType); builder.Append(')'); return builder; } // effects: Modifies builder to contain an escaped version of this private StringBuilder AppendEscapedScalar(StringBuilder builder) { string value = StringUtil.FormatInvariant("{0}", m_scalar); if (value.Contains("'")) { // Deal with strings with ' by doubling it value = value.Replace("'", "''"); } StringUtil.FormatStringBuilder(builder, "'{0}'", value); return builder; } // Returns true if this is semantically equivalent to obj protected override bool IsEqualTo(CellConstant right) { ScalarConstant rightScalarConstant = right as ScalarConstant; if (rightScalarConstant == null) { return false; } return CdpEqualityComparer.DefaultEqualityComparer.Equals(m_scalar, rightScalarConstant.m_scalar); } protected override int GetHash() { if (m_scalar == null) { return 1; } else { return m_scalar.GetHashCode(); } } private void InternalToString(StringBuilder builder, bool isInvariant) { EnumMember enumMember = m_scalar as EnumMember; if (enumMember != null) { builder.Append(enumMember.Name); } else if (m_scalar == null) { builder.Append(isInvariant? "NULL": System.Data.Entity.Strings.ViewGen_Null); } else { builder.Append(StringUtil.FormatInvariant("'{0}'", m_scalar)); } } internal override string ToUserString() { StringBuilder builder = new StringBuilder(); InternalToString(builder, false); return builder.ToString(); } internal override void ToCompactString(StringBuilder builder) { InternalToString(builder, true); } #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
- ConnectionStringSettingsCollection.cs
- DocumentXPathNavigator.cs
- EntityDataSourceDesigner.cs
- ColumnReorderedEventArgs.cs
- UnitySerializationHolder.cs
- RbTree.cs
- Win32.cs
- Int32RectValueSerializer.cs
- VectorCollection.cs
- SoapMessage.cs
- DataServiceKeyAttribute.cs
- counter.cs
- XmlSchemaIdentityConstraint.cs
- SendMailErrorEventArgs.cs
- RecordBuilder.cs
- SafeFindHandle.cs
- XpsInterleavingPolicy.cs
- AtomPub10ServiceDocumentFormatter.cs
- EditorPartDesigner.cs
- StyleBamlRecordReader.cs
- XmlChildEnumerator.cs
- PersistenceException.cs
- tabpagecollectioneditor.cs
- BinHexEncoder.cs
- DataGridBoolColumn.cs
- TreeView.cs
- PrintingPermissionAttribute.cs
- SQlBooleanStorage.cs
- TreeChangeInfo.cs
- PeerCollaboration.cs
- SerializationException.cs
- XmlProcessingInstruction.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- CodeMemberField.cs
- StringComparer.cs
- SimpleFileLog.cs
- DesignerView.Commands.cs
- ColorTypeConverter.cs
- Error.cs
- TextMessageEncoder.cs
- SchemaObjectWriter.cs
- IsolatedStorageFilePermission.cs
- CompiledRegexRunner.cs
- InteropAutomationProvider.cs
- PcmConverter.cs
- GridViewRowCollection.cs
- HierarchicalDataSourceControl.cs
- ErrorWebPart.cs
- DateTime.cs
- ImageDrawing.cs
- TrustLevelCollection.cs
- CacheVirtualItemsEvent.cs
- LinkLabelLinkClickedEvent.cs
- BrowserInteropHelper.cs
- CounterCreationDataCollection.cs
- QueryUtil.cs
- MdiWindowListStrip.cs
- ProgressBar.cs
- TraceContext.cs
- BStrWrapper.cs
- Stylesheet.cs
- ParallelTimeline.cs
- SoapMessage.cs
- MsmqElementBase.cs
- RadioButtonAutomationPeer.cs
- AtomMaterializerLog.cs
- LocationSectionRecord.cs
- CroppedBitmap.cs
- XmlCharCheckingReader.cs
- SiteMembershipCondition.cs
- XmlEventCache.cs
- ExceptionUtil.cs
- GenericRootAutomationPeer.cs
- CancelEventArgs.cs
- ListBoxAutomationPeer.cs
- SqlOuterApplyReducer.cs
- StateItem.cs
- DesignerTransaction.cs
- KnowledgeBase.cs
- XhtmlConformanceSection.cs
- ExtensionFile.cs
- ViewRendering.cs
- serverconfig.cs
- DataGridItem.cs
- InputElement.cs
- CompiledQueryCacheKey.cs
- OneOfConst.cs
- RowVisual.cs
- ObjectStateFormatter.cs
- CustomWebEventKey.cs
- OutputScopeManager.cs
- UnionCodeGroup.cs
- ZipPackagePart.cs
- DataMemberAttribute.cs
- FragmentQueryProcessor.cs
- DesignSurfaceManager.cs
- ConfigXmlAttribute.cs
- PowerModeChangedEventArgs.cs
- MediaEntryAttribute.cs
- PerformanceCounterNameAttribute.cs