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
- BoolLiteral.cs
- DbgCompiler.cs
- CollectionBuilder.cs
- Selector.cs
- ObjectListDataBindEventArgs.cs
- DataServiceHostWrapper.cs
- InvalidOleVariantTypeException.cs
- Schema.cs
- HttpClientCertificate.cs
- IdentityModelStringsVersion1.cs
- TextFormatterHost.cs
- SQLInt16Storage.cs
- FrameworkElement.cs
- CallTemplateAction.cs
- ThreadAbortException.cs
- Cell.cs
- PageParserFilter.cs
- DataGridViewCellConverter.cs
- BufferedMessageWriter.cs
- XslCompiledTransform.cs
- JapaneseLunisolarCalendar.cs
- WSDualHttpBindingCollectionElement.cs
- WebResourceAttribute.cs
- DefaultEventAttribute.cs
- TokenizerHelper.cs
- PrintDialog.cs
- OSFeature.cs
- DataBoundControl.cs
- NamedPipeProcessProtocolHandler.cs
- VerticalAlignConverter.cs
- HatchBrush.cs
- SchemaElementLookUpTableEnumerator.cs
- ComponentDesigner.cs
- PenThreadWorker.cs
- ConfigurationManagerInternal.cs
- WinFormsComponentEditor.cs
- DataControlReference.cs
- KeyedCollection.cs
- KeyboardEventArgs.cs
- XappLauncher.cs
- CodeGotoStatement.cs
- ReferenceTypeElement.cs
- CngKey.cs
- StandardToolWindows.cs
- precedingquery.cs
- TableProviderWrapper.cs
- HttpCachePolicyElement.cs
- GroupItemAutomationPeer.cs
- MembershipSection.cs
- StreamReader.cs
- DataGridViewAddColumnDialog.cs
- Zone.cs
- SoundPlayer.cs
- FamilyMap.cs
- SmiMetaData.cs
- PasswordBoxAutomationPeer.cs
- AssemblyBuilder.cs
- Classification.cs
- HtmlAnchor.cs
- XmlIterators.cs
- ToolStripOverflow.cs
- TextWriter.cs
- TraversalRequest.cs
- OdbcTransaction.cs
- ObjectTag.cs
- WebPartEventArgs.cs
- basevalidator.cs
- ErrorHandlerFaultInfo.cs
- TransferMode.cs
- WorkflowInstance.cs
- ColumnTypeConverter.cs
- MatrixTransform3D.cs
- EventPropertyMap.cs
- HwndMouseInputProvider.cs
- SqlRowUpdatingEvent.cs
- _AuthenticationState.cs
- ExecutionEngineException.cs
- NavigateEvent.cs
- ExpressionBuilderCollection.cs
- DataColumnChangeEvent.cs
- FormViewInsertEventArgs.cs
- ObjectDataSourceStatusEventArgs.cs
- AspNetSynchronizationContext.cs
- SchemaDeclBase.cs
- CompilationSection.cs
- ClientUIRequest.cs
- ArrangedElementCollection.cs
- EntityCommandDefinition.cs
- IndentTextWriter.cs
- EtwProvider.cs
- SimpleMailWebEventProvider.cs
- AlternateViewCollection.cs
- SecurityException.cs
- ExceptionValidationRule.cs
- NegatedCellConstant.cs
- PropertyChangedEventManager.cs
- ResXBuildProvider.cs
- ResourceDictionaryCollection.cs
- ButtonRenderer.cs
- controlskin.cs