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
- WindowsTab.cs
- xsdvalidator.cs
- TargetParameterCountException.cs
- Thumb.cs
- SemaphoreSecurity.cs
- CodeTypeDelegate.cs
- DataPointer.cs
- FormViewInsertedEventArgs.cs
- PartDesigner.cs
- LayoutManager.cs
- WindowsFormsSectionHandler.cs
- TextLine.cs
- ProfileGroupSettingsCollection.cs
- DefaultTextStoreTextComposition.cs
- ServiceDeploymentInfo.cs
- XmlExpressionDumper.cs
- UIntPtr.cs
- DataKey.cs
- HttpModuleActionCollection.cs
- RegexFCD.cs
- EntityDataSourceWrapper.cs
- TraceListener.cs
- DeviceContext2.cs
- UserPreferenceChangingEventArgs.cs
- ChildTable.cs
- QilXmlReader.cs
- XmlTextWriter.cs
- PreservationFileWriter.cs
- EntityStoreSchemaGenerator.cs
- XamlLoadErrorInfo.cs
- DesignerSerializationVisibilityAttribute.cs
- CodeCastExpression.cs
- ConfigXmlWhitespace.cs
- ContentValidator.cs
- StyleBamlRecordReader.cs
- AssemblyResourceLoader.cs
- StatusBarItem.cs
- FormView.cs
- TypeConverterHelper.cs
- XmlParserContext.cs
- SerialPort.cs
- DateTimeOffsetConverter.cs
- _AutoWebProxyScriptEngine.cs
- MexTcpBindingElement.cs
- DBDataPermissionAttribute.cs
- AxParameterData.cs
- GeometryCollection.cs
- ClientConfigurationSystem.cs
- BufferedWebEventProvider.cs
- BindingMemberInfo.cs
- CalendarTable.cs
- AuthorizationRule.cs
- ValidationEventArgs.cs
- ValuePattern.cs
- _CookieModule.cs
- XmlReflectionMember.cs
- AlphabetConverter.cs
- DoubleCollectionValueSerializer.cs
- ReadWriteObjectLock.cs
- CopyAttributesAction.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- PnrpPermission.cs
- SizeAnimationUsingKeyFrames.cs
- RoleGroupCollection.cs
- SessionSwitchEventArgs.cs
- BrowsableAttribute.cs
- Pkcs9Attribute.cs
- CharStorage.cs
- FillErrorEventArgs.cs
- mda.cs
- MethodExpr.cs
- DiffuseMaterial.cs
- StaticFileHandler.cs
- ApplicationActivator.cs
- AdPostCacheSubstitution.cs
- UnknownWrapper.cs
- DownloadProgressEventArgs.cs
- DbParameterCollectionHelper.cs
- StrongNameUtility.cs
- EmptyControlCollection.cs
- versioninfo.cs
- FormClosingEvent.cs
- IntegerValidator.cs
- MarkerProperties.cs
- DeadCharTextComposition.cs
- SemanticKeyElement.cs
- TypeUtil.cs
- TextEndOfSegment.cs
- ApplicationFileParser.cs
- TopClause.cs
- StyleSelector.cs
- OracleEncoding.cs
- OperationAbortedException.cs
- RegisterInfo.cs
- RelationshipType.cs
- Matrix3DStack.cs
- DrawingState.cs
- CommonDialog.cs
- Action.cs
- StyleTypedPropertyAttribute.cs