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 / Metadata / ClrPerspective.cs / 1 / ClrPerspective.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....],[....]
//---------------------------------------------------------------------
namespace System.Data.Metadata.Edm
{
using System.Collections.Generic;
using System.Data.Mapping;
using System.Diagnostics;
///
/// Internal helper class for query
///
internal sealed class ClrPerspective : Perspective
{
private EntityContainer _defaultContainer;
#region Constructors
///
/// Creates a new instance of perspective class so that query can work
/// ignorant of all spaces
///
///
internal ClrPerspective(MetadataWorkspace metadataWorkspace)
: base(metadataWorkspace, DataSpace.CSpace)
{
}
#endregion //Constructors
#region Methods
///
/// Given a clrType attempt to return the corresponding target type from
/// the worksapce
///
/// The clr type to resolve
/// an out param for the typeUsage to be resolved to
/// true if a TypeUsage can be found for the target type
internal bool TryGetType(Type clrType, out TypeUsage outTypeUsage)
{
return TryGetTypeByName(clrType.FullName,
false /*ignoreCase*/,
out outTypeUsage);
}
///
/// Given the type in the target space and the member name in the source space,
/// get the corresponding member in the target space
/// For e.g. consider a Conceptual Type Foo with a member bar and a CLR type
/// XFoo with a member YBar. If one has a reference to Foo one can
/// invoke GetMember(Foo,"YBar") to retrieve the member metadata for bar
///
/// The type in the target perspective
/// the name of the member in the source perspective
/// true for case-insensitive lookup
/// returns the edmMember if a match is found
/// true if a match is found, otherwise false
internal override bool TryGetMember(StructuralType type, String memberName, bool ignoreCase, out EdmMember outMember)
{
outMember = null;
Map map = null;
if (this.MetadataWorkspace.TryGetMap(type, DataSpace.OCSpace, out map))
{
ObjectTypeMapping objectTypeMap = map as ObjectTypeMapping;
if (objectTypeMap!=null)
{
ObjectMemberMapping objPropertyMapping = objectTypeMap.GetMemberMapForClrMember(memberName, ignoreCase);
if (null != objPropertyMapping)
{
outMember = objPropertyMapping.EdmMember;
return true;
}
}
}
return false;
}
///
/// Look up a type in the target data space based upon the fullName
///
/// fullName
/// true for case-insensitive lookup
/// The type usage object to return
/// True if the retrieval succeeded
internal override bool TryGetTypeByName(string fullName, bool ignoreCase, out TypeUsage typeUsage)
{
typeUsage = null;
Map map = null;
// From ClrPerspective, we should not allow anything from SSpace. So make sure that the CSpace type does not
// have the Target attribute
if (this.MetadataWorkspace.TryGetMap(fullName, DataSpace.OSpace, ignoreCase, DataSpace.OCSpace, out map))
{
// Check if it's primitive type, if so, then use the MetadataWorkspace to get the mapped primitive type
if (map.EdmItem.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType)
{
// Reassign the variable with the provider primitive type, then create the type usage
PrimitiveType primitiveType = this.MetadataWorkspace.GetMappedPrimitiveType(((PrimitiveType)map.EdmItem).PrimitiveTypeKind, DataSpace.CSpace);
if (primitiveType != null)
{
typeUsage = EdmProviderManifest.Instance.GetCanonicalModelTypeUsage(primitiveType.PrimitiveTypeKind);
}
}
else
{
Debug.Assert(((GlobalItem)map.EdmItem).DataSpace == DataSpace.CSpace);
typeUsage = GetMappedTypeUsage(map);
}
}
return (null != typeUsage);
}
///
/// get the default container
///
/// The default container
internal override EntityContainer GetDefaultContainer()
{
return _defaultContainer;
}
internal void SetDefaultContainer(string defaultContainerName)
{
EntityContainer container = null;
if (!String.IsNullOrEmpty(defaultContainerName))
{
if (!MetadataWorkspace.TryGetEntityContainer(defaultContainerName, DataSpace.CSpace, out container))
{
throw EntityUtil.InvalidDefaultContainerName("defaultContainerName", defaultContainerName);
}
}
_defaultContainer = container;
}
///
/// Given a map, dereference the EdmItem, ensure that it is
/// an EdmType and return a TypeUsage for the type, otherwise
/// return null.
///
/// The OC map to use to get the EdmType
/// A TypeUsage for the mapped EdmType or null if no EdmType was mapped
private static TypeUsage GetMappedTypeUsage(Map map)
{
TypeUsage typeUsage = null;
if (null != map)
{
MetadataItem item = map.EdmItem;
EdmType edmItem = item as EdmType;
if (null != item && edmItem!=null)
{
typeUsage = TypeUsage.Create(edmItem);
}
}
return typeUsage;
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....],[....]
//---------------------------------------------------------------------
namespace System.Data.Metadata.Edm
{
using System.Collections.Generic;
using System.Data.Mapping;
using System.Diagnostics;
///
/// Internal helper class for query
///
internal sealed class ClrPerspective : Perspective
{
private EntityContainer _defaultContainer;
#region Constructors
///
/// Creates a new instance of perspective class so that query can work
/// ignorant of all spaces
///
///
internal ClrPerspective(MetadataWorkspace metadataWorkspace)
: base(metadataWorkspace, DataSpace.CSpace)
{
}
#endregion //Constructors
#region Methods
///
/// Given a clrType attempt to return the corresponding target type from
/// the worksapce
///
/// The clr type to resolve
/// an out param for the typeUsage to be resolved to
/// true if a TypeUsage can be found for the target type
internal bool TryGetType(Type clrType, out TypeUsage outTypeUsage)
{
return TryGetTypeByName(clrType.FullName,
false /*ignoreCase*/,
out outTypeUsage);
}
///
/// Given the type in the target space and the member name in the source space,
/// get the corresponding member in the target space
/// For e.g. consider a Conceptual Type Foo with a member bar and a CLR type
/// XFoo with a member YBar. If one has a reference to Foo one can
/// invoke GetMember(Foo,"YBar") to retrieve the member metadata for bar
///
/// The type in the target perspective
/// the name of the member in the source perspective
/// true for case-insensitive lookup
/// returns the edmMember if a match is found
/// true if a match is found, otherwise false
internal override bool TryGetMember(StructuralType type, String memberName, bool ignoreCase, out EdmMember outMember)
{
outMember = null;
Map map = null;
if (this.MetadataWorkspace.TryGetMap(type, DataSpace.OCSpace, out map))
{
ObjectTypeMapping objectTypeMap = map as ObjectTypeMapping;
if (objectTypeMap!=null)
{
ObjectMemberMapping objPropertyMapping = objectTypeMap.GetMemberMapForClrMember(memberName, ignoreCase);
if (null != objPropertyMapping)
{
outMember = objPropertyMapping.EdmMember;
return true;
}
}
}
return false;
}
///
/// Look up a type in the target data space based upon the fullName
///
/// fullName
/// true for case-insensitive lookup
/// The type usage object to return
/// True if the retrieval succeeded
internal override bool TryGetTypeByName(string fullName, bool ignoreCase, out TypeUsage typeUsage)
{
typeUsage = null;
Map map = null;
// From ClrPerspective, we should not allow anything from SSpace. So make sure that the CSpace type does not
// have the Target attribute
if (this.MetadataWorkspace.TryGetMap(fullName, DataSpace.OSpace, ignoreCase, DataSpace.OCSpace, out map))
{
// Check if it's primitive type, if so, then use the MetadataWorkspace to get the mapped primitive type
if (map.EdmItem.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType)
{
// Reassign the variable with the provider primitive type, then create the type usage
PrimitiveType primitiveType = this.MetadataWorkspace.GetMappedPrimitiveType(((PrimitiveType)map.EdmItem).PrimitiveTypeKind, DataSpace.CSpace);
if (primitiveType != null)
{
typeUsage = EdmProviderManifest.Instance.GetCanonicalModelTypeUsage(primitiveType.PrimitiveTypeKind);
}
}
else
{
Debug.Assert(((GlobalItem)map.EdmItem).DataSpace == DataSpace.CSpace);
typeUsage = GetMappedTypeUsage(map);
}
}
return (null != typeUsage);
}
///
/// get the default container
///
/// The default container
internal override EntityContainer GetDefaultContainer()
{
return _defaultContainer;
}
internal void SetDefaultContainer(string defaultContainerName)
{
EntityContainer container = null;
if (!String.IsNullOrEmpty(defaultContainerName))
{
if (!MetadataWorkspace.TryGetEntityContainer(defaultContainerName, DataSpace.CSpace, out container))
{
throw EntityUtil.InvalidDefaultContainerName("defaultContainerName", defaultContainerName);
}
}
_defaultContainer = container;
}
///
/// Given a map, dereference the EdmItem, ensure that it is
/// an EdmType and return a TypeUsage for the type, otherwise
/// return null.
///
/// The OC map to use to get the EdmType
/// A TypeUsage for the mapped EdmType or null if no EdmType was mapped
private static TypeUsage GetMappedTypeUsage(Map map)
{
TypeUsage typeUsage = null;
if (null != map)
{
MetadataItem item = map.EdmItem;
EdmType edmItem = item as EdmType;
if (null != item && edmItem!=null)
{
typeUsage = TypeUsage.Create(edmItem);
}
}
return typeUsage;
}
#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
- DispatcherExceptionFilterEventArgs.cs
- InputLanguageProfileNotifySink.cs
- ReachDocumentReferenceCollectionSerializer.cs
- Globals.cs
- ZipIOModeEnforcingStream.cs
- processwaithandle.cs
- FramingChannels.cs
- WebPartVerb.cs
- SyndicationItem.cs
- SerializationHelper.cs
- BadImageFormatException.cs
- DataGrid.cs
- RowUpdatingEventArgs.cs
- DataContext.cs
- Rule.cs
- PropertyRecord.cs
- QilFactory.cs
- DefaultTraceListener.cs
- DataServiceRequestException.cs
- EditorBrowsableAttribute.cs
- EntityTypeEmitter.cs
- XmlDataLoader.cs
- __ComObject.cs
- StackBuilderSink.cs
- HttpErrorTraceRecord.cs
- TextInfo.cs
- UIServiceHelper.cs
- EmptyEnumerator.cs
- WorkflowViewManager.cs
- ChtmlTextWriter.cs
- Rectangle.cs
- SiteMapHierarchicalDataSourceView.cs
- XmlIncludeAttribute.cs
- WorkflowFileItem.cs
- ConfigXmlElement.cs
- StringAnimationBase.cs
- PolyQuadraticBezierSegment.cs
- ProcessInputEventArgs.cs
- Function.cs
- CodeTypeDeclaration.cs
- HttpHandlerActionCollection.cs
- WindowsGraphicsCacheManager.cs
- SoapAttributeOverrides.cs
- HttpClientCertificate.cs
- HandleCollector.cs
- EnumUnknown.cs
- HttpProfileGroupBase.cs
- FrameworkContextData.cs
- RelativeSource.cs
- VideoDrawing.cs
- SolidColorBrush.cs
- IndependentlyAnimatedPropertyMetadata.cs
- DbConnectionPoolIdentity.cs
- ClickablePoint.cs
- XmlDictionaryString.cs
- StorageEntitySetMapping.cs
- ComponentCommands.cs
- WindowsFormsLinkLabel.cs
- ProtocolsConfiguration.cs
- DesignConnectionCollection.cs
- FlowDocumentFormatter.cs
- DiscreteKeyFrames.cs
- FSWPathEditor.cs
- TypeNameConverter.cs
- DbDataReader.cs
- VisualStyleElement.cs
- MethodImplAttribute.cs
- FrameAutomationPeer.cs
- SimpleHandlerBuildProvider.cs
- XmlAtomErrorReader.cs
- MultiBindingExpression.cs
- FormViewModeEventArgs.cs
- ApplyImportsAction.cs
- WSSecurityPolicy.cs
- SqlMethodCallConverter.cs
- EventSource.cs
- StringAnimationBase.cs
- HtmlWindow.cs
- XmlSchemaExternal.cs
- SharedPersonalizationStateInfo.cs
- CodeGenHelper.cs
- ConnectionPoolManager.cs
- CollectionBase.cs
- PrintPreviewControl.cs
- ClearCollection.cs
- CustomCategoryAttribute.cs
- AsyncResult.cs
- RelationshipConstraintValidator.cs
- Psha1DerivedKeyGeneratorHelper.cs
- CodeDirectoryCompiler.cs
- CodeEventReferenceExpression.cs
- ReaderWriterLock.cs
- FixedDocumentSequencePaginator.cs
- TextContainerChangeEventArgs.cs
- SqlMethodTransformer.cs
- RuntimeTransactionHandle.cs
- SurrogateDataContract.cs
- FixedSOMTable.cs
- WorkflowPersistenceService.cs
- ObjectItemCachedAssemblyLoader.cs