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
- DiffuseMaterial.cs
- UserControlCodeDomTreeGenerator.cs
- XmlSchemaValidationException.cs
- SqlClientWrapperSmiStream.cs
- PKCS1MaskGenerationMethod.cs
- EntitySet.cs
- DoubleCollectionConverter.cs
- DataList.cs
- CoreSwitches.cs
- PowerStatus.cs
- SmtpTransport.cs
- WebUtil.cs
- AnimationClock.cs
- ServiceConfigurationTraceRecord.cs
- DbParameterCollectionHelper.cs
- CatalogPartCollection.cs
- LogExtentCollection.cs
- MsmqInputSessionChannel.cs
- SizeIndependentAnimationStorage.cs
- ObjectStateEntryOriginalDbUpdatableDataRecord.cs
- OrderByBuilder.cs
- StreamSecurityUpgradeAcceptorAsyncResult.cs
- CollectionTypeElement.cs
- Attribute.cs
- ServiceHttpHandlerFactory.cs
- CompilerInfo.cs
- IdentityManager.cs
- WindowsScrollBar.cs
- WebContext.cs
- MaskDescriptors.cs
- DataKey.cs
- BaseParser.cs
- GroupItem.cs
- XmlEnumAttribute.cs
- QilPatternFactory.cs
- DataStreamFromComStream.cs
- ADMembershipProvider.cs
- HttpCookieCollection.cs
- ExpressionNode.cs
- BatchServiceHost.cs
- DayRenderEvent.cs
- FormViewCommandEventArgs.cs
- FixedPageAutomationPeer.cs
- xsdvalidator.cs
- RegionInfo.cs
- DataControlCommands.cs
- HttpConfigurationContext.cs
- Camera.cs
- ApplicationSettingsBase.cs
- BasicExpressionVisitor.cs
- DetailsViewInsertEventArgs.cs
- WebDisplayNameAttribute.cs
- StringUtil.cs
- HitTestWithGeometryDrawingContextWalker.cs
- IIS7WorkerRequest.cs
- Size.cs
- WizardStepBase.cs
- Size.cs
- AnnotationHighlightLayer.cs
- basecomparevalidator.cs
- AccessDataSourceView.cs
- HttpListenerException.cs
- ToolBar.cs
- ResourceCollectionInfo.cs
- TemplateKey.cs
- WindowsNonControl.cs
- XslVisitor.cs
- FrameworkTemplate.cs
- AtomServiceDocumentSerializer.cs
- PerfCounterSection.cs
- DrawItemEvent.cs
- ServiceModelExtensionCollectionElement.cs
- DataGridViewColumn.cs
- OraclePermission.cs
- DecoderFallback.cs
- ErasingStroke.cs
- StylusPointPropertyUnit.cs
- MetaColumn.cs
- UnauthorizedWebPart.cs
- TrackingParticipant.cs
- CharEntityEncoderFallback.cs
- EditorResources.cs
- StateBag.cs
- InvalidProgramException.cs
- RadioButtonFlatAdapter.cs
- HwndStylusInputProvider.cs
- ChtmlTextWriter.cs
- InkCanvas.cs
- Facet.cs
- DocumentViewerBase.cs
- OlePropertyStructs.cs
- DefaultTextStore.cs
- WebServiceMethodData.cs
- ApplicationDirectory.cs
- PropertyKey.cs
- Compilation.cs
- ListViewSelectEventArgs.cs
- LineVisual.cs
- FileNotFoundException.cs
- ErrorHandler.cs