Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Structures / TypeConstant.cs / 1305376 / TypeConstant.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Text;
using System.Collections.Generic;
using System.Data.Mapping.ViewGeneration.CqlGeneration;
using System.Data.Common;
using System.Data.Common.Utils;
using System.Data.Metadata.Edm;
using System.Diagnostics;
namespace System.Data.Mapping.ViewGeneration.Structures
{
// A constant for storing type values, e.g., a type constant is used to
// denotes (say) a Person type, Address type, etc. It essentially
// encapsulates a CDM Type
internal class TypeConstant : Constant
{
#region Constructor
// effects: Creates a type constant corresponding to "type"
internal TypeConstant(EdmType type)
{
m_cdmType = type;
}
#endregion
#region Fields
// The CDM type denoted by this type constant
private EdmType m_cdmType;
#endregion
#region Properties
// effects: Returns the CDM type corresponding to this
internal EdmType CdmType
{
get { return m_cdmType; }
}
#endregion
#region Methods
// effects: Given a projectedSlot that contributes to outputMember in
// the output extent view, generates a constructor expression for
// outputMember's type, i.e, an expression of the form "Type(....)"
// If refscope is non-null, instead of constructing an Entity or
// Complex type, constructs a reference
internal override StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias)
{
// Gather the fields for a constructor or a Ref expression
List fields = new List();
EntitySet refScope = outputMember.GetScopeOfRelationEnd();
EntityType refEntityType = null;
if (refScope != null)
{
// Construct a scoped reference: CreateRef(CPerson1, row(pid1, pid2))
EntityType entityType = refScope.ElementType;
refEntityType = (EntityType)(((RefType)outputMember.EdmType).ElementType);
builder.Append("CreateRef(");
CqlWriter.AppendEscapedQualifiedName(builder, refScope.EntityContainer.Name, refScope.Name);
builder.Append(", row(");
foreach (EdmMember keyMember in entityType.KeyMembers)
{
// Given the member, we need its aliased name
MemberPath memberPath = new MemberPath(outputMember, keyMember);
string fullFieldAlias = CqlWriter.GetQualifiedName(blockAlias, memberPath.CqlFieldAlias);
fields.Add(fullFieldAlias);
}
}
else
{
// Construct an entity/complex/Association type in the Members order
// for fields: CPerson(CPerson1_Pid, CPerson1_Name)
// It better be a structural type
StructuralType structuralType = (StructuralType)m_cdmType;
foreach (EdmMember member in Helper.GetAllStructuralMembers(structuralType))
{
// Given the member, we need its aliased name: CPerson1_Pid
MemberPath memberPath = new MemberPath(outputMember, member);
string fullFieldAlias = CqlWriter.GetQualifiedName(blockAlias, memberPath.CqlFieldAlias);
fields.Add(fullFieldAlias);
}
// Constructor call for the constructedType
CqlWriter.AppendEscapedTypeName(builder, m_cdmType);
builder.Append('(');
}
StringUtil.ToSeparatedString(builder, fields, ", ", null);
builder.Append(')');
if (refScope != null)
{
Debug.Assert(refEntityType != null);
builder.Append(",");
CqlWriter.AppendEscapedTypeName(builder, refEntityType);
builder.Append(')');
}
return builder;
}
#endregion
#region Public Override Methods for object and String methods
protected override bool IsEqualTo(Constant right)
{
TypeConstant rightTypeConstant = right as TypeConstant;
if (rightTypeConstant == null)
{
return false;
}
return m_cdmType == rightTypeConstant.m_cdmType;
}
protected override int GetHash()
{
if (m_cdmType == null)
{ // null type constant
return 0;
}
else
{
return m_cdmType.GetHashCode();
}
}
private void InternalToString(StringBuilder builder, bool isInvariant)
{
if (m_cdmType == null)
{ // NULL type constant
builder.Append(isInvariant ? "NULL" : System.Data.Entity.Strings.ViewGen_Null);
}
else
{
builder.Append(m_cdmType.Name);
}
}
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.Collections.Generic;
using System.Data.Mapping.ViewGeneration.CqlGeneration;
using System.Data.Common;
using System.Data.Common.Utils;
using System.Data.Metadata.Edm;
using System.Diagnostics;
namespace System.Data.Mapping.ViewGeneration.Structures
{
// A constant for storing type values, e.g., a type constant is used to
// denotes (say) a Person type, Address type, etc. It essentially
// encapsulates a CDM Type
internal class TypeConstant : Constant
{
#region Constructor
// effects: Creates a type constant corresponding to "type"
internal TypeConstant(EdmType type)
{
m_cdmType = type;
}
#endregion
#region Fields
// The CDM type denoted by this type constant
private EdmType m_cdmType;
#endregion
#region Properties
// effects: Returns the CDM type corresponding to this
internal EdmType CdmType
{
get { return m_cdmType; }
}
#endregion
#region Methods
// effects: Given a projectedSlot that contributes to outputMember in
// the output extent view, generates a constructor expression for
// outputMember's type, i.e, an expression of the form "Type(....)"
// If refscope is non-null, instead of constructing an Entity or
// Complex type, constructs a reference
internal override StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias)
{
// Gather the fields for a constructor or a Ref expression
List fields = new List();
EntitySet refScope = outputMember.GetScopeOfRelationEnd();
EntityType refEntityType = null;
if (refScope != null)
{
// Construct a scoped reference: CreateRef(CPerson1, row(pid1, pid2))
EntityType entityType = refScope.ElementType;
refEntityType = (EntityType)(((RefType)outputMember.EdmType).ElementType);
builder.Append("CreateRef(");
CqlWriter.AppendEscapedQualifiedName(builder, refScope.EntityContainer.Name, refScope.Name);
builder.Append(", row(");
foreach (EdmMember keyMember in entityType.KeyMembers)
{
// Given the member, we need its aliased name
MemberPath memberPath = new MemberPath(outputMember, keyMember);
string fullFieldAlias = CqlWriter.GetQualifiedName(blockAlias, memberPath.CqlFieldAlias);
fields.Add(fullFieldAlias);
}
}
else
{
// Construct an entity/complex/Association type in the Members order
// for fields: CPerson(CPerson1_Pid, CPerson1_Name)
// It better be a structural type
StructuralType structuralType = (StructuralType)m_cdmType;
foreach (EdmMember member in Helper.GetAllStructuralMembers(structuralType))
{
// Given the member, we need its aliased name: CPerson1_Pid
MemberPath memberPath = new MemberPath(outputMember, member);
string fullFieldAlias = CqlWriter.GetQualifiedName(blockAlias, memberPath.CqlFieldAlias);
fields.Add(fullFieldAlias);
}
// Constructor call for the constructedType
CqlWriter.AppendEscapedTypeName(builder, m_cdmType);
builder.Append('(');
}
StringUtil.ToSeparatedString(builder, fields, ", ", null);
builder.Append(')');
if (refScope != null)
{
Debug.Assert(refEntityType != null);
builder.Append(",");
CqlWriter.AppendEscapedTypeName(builder, refEntityType);
builder.Append(')');
}
return builder;
}
#endregion
#region Public Override Methods for object and String methods
protected override bool IsEqualTo(Constant right)
{
TypeConstant rightTypeConstant = right as TypeConstant;
if (rightTypeConstant == null)
{
return false;
}
return m_cdmType == rightTypeConstant.m_cdmType;
}
protected override int GetHash()
{
if (m_cdmType == null)
{ // null type constant
return 0;
}
else
{
return m_cdmType.GetHashCode();
}
}
private void InternalToString(StringBuilder builder, bool isInvariant)
{
if (m_cdmType == null)
{ // NULL type constant
builder.Append(isInvariant ? "NULL" : System.Data.Entity.Strings.ViewGen_Null);
}
else
{
builder.Append(m_cdmType.Name);
}
}
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
- DataGridViewImageColumn.cs
- DeriveBytes.cs
- CompositeScriptReference.cs
- AssemblyResolver.cs
- HtmlTitle.cs
- SystemEvents.cs
- XmlTextReaderImpl.cs
- IPAddressCollection.cs
- Publisher.cs
- SessionIDManager.cs
- EnvironmentPermission.cs
- SiteIdentityPermission.cs
- WeakEventManager.cs
- XPathNodeHelper.cs
- ITextView.cs
- activationcontext.cs
- HttpCachePolicyElement.cs
- Subtree.cs
- QueryInterceptorAttribute.cs
- QuadraticBezierSegment.cs
- DataTableReaderListener.cs
- WebRequestModulesSection.cs
- SerializableAttribute.cs
- RuntimeConfig.cs
- ProxyGenerationError.cs
- AddInContractAttribute.cs
- SimpleApplicationHost.cs
- TableRowGroupCollection.cs
- WorkflowQueue.cs
- DesignerView.Commands.cs
- KeyValueConfigurationCollection.cs
- DataPointer.cs
- MessageParameterAttribute.cs
- StandardMenuStripVerb.cs
- SlotInfo.cs
- FieldAccessException.cs
- PropertyItemInternal.cs
- BeginStoryboard.cs
- CompilationPass2TaskInternal.cs
- WebPartCancelEventArgs.cs
- CriticalFinalizerObject.cs
- WebDescriptionAttribute.cs
- DynamicHyperLink.cs
- Msmq4SubqueuePoisonHandler.cs
- ImageBrush.cs
- ExitEventArgs.cs
- EventProxy.cs
- XmlSchemaExporter.cs
- HuffCodec.cs
- XPathExpr.cs
- OleStrCAMarshaler.cs
- SecUtil.cs
- CheckedListBox.cs
- XsdSchemaFileEditor.cs
- MsmqInputMessagePool.cs
- BamlReader.cs
- PrintDialogException.cs
- XmlReflectionImporter.cs
- SamlDoNotCacheCondition.cs
- SingleStorage.cs
- Selection.cs
- IsolatedStorageFilePermission.cs
- BitmapEffectGroup.cs
- IssuanceTokenProviderBase.cs
- Point3DCollectionValueSerializer.cs
- DefinitionProperties.cs
- AssertHelper.cs
- BrowserInteropHelper.cs
- ExcludePathInfo.cs
- SafeMemoryMappedViewHandle.cs
- BitmapEffectGroup.cs
- LoadRetryStrategyFactory.cs
- ArgumentNullException.cs
- BooleanToVisibilityConverter.cs
- UIElement.cs
- StateRuntime.cs
- SqlDataSourceCache.cs
- ItemMap.cs
- WindowsFont.cs
- mediapermission.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- Debug.cs
- SecurityMessageProperty.cs
- AudioFileOut.cs
- InheritanceUI.cs
- FormsAuthenticationTicket.cs
- FixedElement.cs
- AQNBuilder.cs
- DataViewSettingCollection.cs
- CustomErrorCollection.cs
- ServiceNameCollection.cs
- RowUpdatingEventArgs.cs
- RangeContentEnumerator.cs
- CacheOutputQuery.cs
- NamespaceExpr.cs
- PipelineModuleStepContainer.cs
- FrameSecurityDescriptor.cs
- SafeFreeMibTable.cs
- PlainXmlDeserializer.cs
- TypedRowGenerator.cs