Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Objects / ProxyDataContractResolver.cs / 1305376 / ProxyDataContractResolver.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Runtime.Serialization; namespace System.Data.Objects { ////// A DataContractResolver that knows how to resolve proxy types created for persistent /// ignorant classes to their base types. This is used with the DataContractSerializer. /// public class ProxyDataContractResolver : DataContractResolver { private XsdDataContractExporter _exporter = new XsdDataContractExporter(); public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver) { EntityUtil.CheckStringArgument(typeName, "typeName"); EntityUtil.CheckStringArgument(typeNamespace, "typeNamespace"); EntityUtil.CheckArgumentNull(declaredType, "declaredType"); EntityUtil.CheckArgumentNull(knownTypeResolver, "knownTypeResolver"); return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType ,null); } public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace) { EntityUtil.CheckArgumentNull(dataContractType, "dataContractType"); EntityUtil.CheckArgumentNull(declaredType, "declaredType"); EntityUtil.CheckArgumentNull(knownTypeResolver, "knownTypeResolver"); Type nonProxyType = ObjectContext.GetObjectType(dataContractType); if (nonProxyType != dataContractType) { // Type was a proxy type, so map the name to the non-proxy name XmlQualifiedName qualifiedName = _exporter.GetSchemaTypeName(nonProxyType); XmlDictionary dictionary = new XmlDictionary(2); typeName = new XmlDictionaryString(dictionary, qualifiedName.Name, 0); typeNamespace = new XmlDictionaryString(dictionary, qualifiedName.Namespace, 1); return true; } else { // Type was not a proxy type, so do the default return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Runtime.Serialization; namespace System.Data.Objects { ////// A DataContractResolver that knows how to resolve proxy types created for persistent /// ignorant classes to their base types. This is used with the DataContractSerializer. /// public class ProxyDataContractResolver : DataContractResolver { private XsdDataContractExporter _exporter = new XsdDataContractExporter(); public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver) { EntityUtil.CheckStringArgument(typeName, "typeName"); EntityUtil.CheckStringArgument(typeNamespace, "typeNamespace"); EntityUtil.CheckArgumentNull(declaredType, "declaredType"); EntityUtil.CheckArgumentNull(knownTypeResolver, "knownTypeResolver"); return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType ,null); } public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace) { EntityUtil.CheckArgumentNull(dataContractType, "dataContractType"); EntityUtil.CheckArgumentNull(declaredType, "declaredType"); EntityUtil.CheckArgumentNull(knownTypeResolver, "knownTypeResolver"); Type nonProxyType = ObjectContext.GetObjectType(dataContractType); if (nonProxyType != dataContractType) { // Type was a proxy type, so map the name to the non-proxy name XmlQualifiedName qualifiedName = _exporter.GetSchemaTypeName(nonProxyType); XmlDictionary dictionary = new XmlDictionary(2); typeName = new XmlDictionaryString(dictionary, qualifiedName.Name, 0); typeNamespace = new XmlDictionaryString(dictionary, qualifiedName.Namespace, 1); return true; } else { // Type was not a proxy type, so do the default return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace); } } } } // 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
- WizardStepBase.cs
- XmlSchemaIdentityConstraint.cs
- CompModSwitches.cs
- Convert.cs
- BodyWriter.cs
- OuterGlowBitmapEffect.cs
- CultureNotFoundException.cs
- BaseParser.cs
- LinkButton.cs
- ADMembershipProvider.cs
- OdbcConnectionStringbuilder.cs
- SharedDp.cs
- ForeignKeyFactory.cs
- ValueUnavailableException.cs
- UnsafeNativeMethods.cs
- CryptoKeySecurity.cs
- FontStyle.cs
- HostingEnvironmentWrapper.cs
- ErrorProvider.cs
- namescope.cs
- BridgeDataReader.cs
- StorageScalarPropertyMapping.cs
- RemoveStoryboard.cs
- Brush.cs
- X509Certificate2Collection.cs
- ClientTargetSection.cs
- _ProxyRegBlob.cs
- SelectionItemPattern.cs
- WorkflowTransactionService.cs
- IPCCacheManager.cs
- EntityDataSourceDesigner.cs
- ViewgenGatekeeper.cs
- ShapingEngine.cs
- PartitionResolver.cs
- WsatServiceAddress.cs
- SafeFileHandle.cs
- GridViewItemAutomationPeer.cs
- ScalarType.cs
- CodePrimitiveExpression.cs
- LinkClickEvent.cs
- StaticSiteMapProvider.cs
- DynamicResourceExtension.cs
- PropertyCollection.cs
- RelatedImageListAttribute.cs
- ComplexTypeEmitter.cs
- AdRotator.cs
- TypeSchema.cs
- ReachDocumentReferenceCollectionSerializerAsync.cs
- SqlDataSourceCustomCommandEditor.cs
- RetrieveVirtualItemEventArgs.cs
- FillErrorEventArgs.cs
- ErrorHandlerModule.cs
- BinaryConverter.cs
- Expander.cs
- StringDictionary.cs
- EventEntry.cs
- TypeHelpers.cs
- BooleanConverter.cs
- ColumnClickEvent.cs
- DynamicUpdateCommand.cs
- WindowsIdentity.cs
- DataStreamFromComStream.cs
- URLString.cs
- TagMapCollection.cs
- TreeNodeConverter.cs
- MapPathBasedVirtualPathProvider.cs
- TableAdapterManagerHelper.cs
- mediaclock.cs
- GeneratedContractType.cs
- TextViewSelectionProcessor.cs
- EntityCommandCompilationException.cs
- ToolStripSettings.cs
- WebBaseEventKeyComparer.cs
- Documentation.cs
- ExpressionBuilderContext.cs
- SqlCacheDependency.cs
- _AcceptOverlappedAsyncResult.cs
- MgmtConfigurationRecord.cs
- BehaviorService.cs
- HttpCapabilitiesEvaluator.cs
- SQLBytesStorage.cs
- ObjectTypeMapping.cs
- FileRegion.cs
- Encoder.cs
- SequentialUshortCollection.cs
- Point3DAnimationUsingKeyFrames.cs
- BaseCodePageEncoding.cs
- OleDbPropertySetGuid.cs
- ItemDragEvent.cs
- DesignerImageAdapter.cs
- XomlSerializationHelpers.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- TemplateNameScope.cs
- ClientBuildManager.cs
- HandlerFactoryCache.cs
- VScrollProperties.cs
- RelationshipDetailsRow.cs
- WebPartCatalogAddVerb.cs
- DesignerFrame.cs