Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / XmlSerializerObjectSerializer.cs / 2 / XmlSerializerObjectSerializer.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System; using System.Xml; using System.ServiceModel; using System.Xml.Serialization; using System.Collections.Generic; using System.Runtime.Serialization; using System.ServiceModel.Description; internal class XmlSerializerObjectSerializer : XmlObjectSerializer { XmlSerializer serializer; Type rootType; string rootName; string rootNamespace; bool isSerializerSetExplicit = false; internal XmlSerializerObjectSerializer(Type type) { Initialize(type, null /*rootName*/, null /*rootNamespace*/, null /*xmlSerializer*/); } internal XmlSerializerObjectSerializer(Type type, XmlQualifiedName qualifiedName, XmlSerializer xmlSerializer) { if (qualifiedName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("qualifiedName"); } Initialize(type, qualifiedName.Name, qualifiedName.Namespace, xmlSerializer); } void Initialize(Type type, string rootName, string rootNamespace, XmlSerializer xmlSerializer) { if (type == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("type"); } this.rootType = type; this.rootName = rootName; this.rootNamespace = rootNamespace == null ? string.Empty : rootNamespace; this.serializer = xmlSerializer; if (this.serializer == null) { if (this.rootName == null) this.serializer = new XmlSerializer(type); else { XmlRootAttribute xmlRoot = new XmlRootAttribute(); xmlRoot.ElementName = this.rootName; xmlRoot.Namespace = this.rootNamespace; this.serializer = new XmlSerializer(type, xmlRoot); } } else isSerializerSetExplicit = true; //try to get rootName and rootNamespace from type since root name not set explicitly if (this.rootName == null) { XmlTypeMapping mapping = new XmlReflectionImporter().ImportTypeMapping(this.rootType); this.rootName = mapping.ElementName; this.rootNamespace = mapping.Namespace; } } public override void WriteObject(XmlDictionaryWriter writer, object graph) { if (this.isSerializerSetExplicit) this.serializer.Serialize(writer, new object[] { graph }); else this.serializer.Serialize(writer, graph); } public override void WriteStartObject(XmlDictionaryWriter writer, object graph) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public override void WriteObjectContent(XmlDictionaryWriter writer, object graph) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public override void WriteEndObject(XmlDictionaryWriter writer) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName) { if (this.isSerializerSetExplicit) { object [] deserializedObjects = (object[])this.serializer.Deserialize(reader); if (deserializedObjects != null && deserializedObjects.Length > 0) return deserializedObjects[0]; else return null; } else return this.serializer.Deserialize(reader); } public override bool IsStartObject(XmlDictionaryReader reader) { if (reader == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); reader.MoveToElement(); if (this.rootName != null) { return reader.IsStartElement(this.rootName, this.rootNamespace); } else { return reader.IsStartElement(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ContainerUtilities.cs
- ForceCopyBuildProvider.cs
- NonNullItemCollection.cs
- TextServicesDisplayAttribute.cs
- UIServiceHelper.cs
- CrossSiteScriptingValidation.cs
- ThrowOnMultipleAssignment.cs
- UriExt.cs
- InputManager.cs
- VerificationAttribute.cs
- EntityDesignPluralizationHandler.cs
- PathFigureCollectionValueSerializer.cs
- XmlUrlResolver.cs
- BitmapMetadata.cs
- OperandQuery.cs
- SubqueryTrackingVisitor.cs
- CalendarModeChangedEventArgs.cs
- sqlcontext.cs
- ClientSideQueueItem.cs
- XmlDesignerDataSourceView.cs
- DirectoryNotFoundException.cs
- MetaTable.cs
- ToolboxItemAttribute.cs
- HtmlImage.cs
- MarshalByRefObject.cs
- LinqDataSourceSelectEventArgs.cs
- Errors.cs
- Invariant.cs
- ExtendedPropertyInfo.cs
- ModelItemDictionaryImpl.cs
- XmlSchemaParticle.cs
- ManagedFilter.cs
- TypeTypeConverter.cs
- TreeNodeStyleCollection.cs
- CodeCatchClause.cs
- InputBindingCollection.cs
- NativeMethods.cs
- AtlasWeb.Designer.cs
- PartitionerQueryOperator.cs
- NamedObject.cs
- SqlConnectionPoolGroupProviderInfo.cs
- StrongNameUtility.cs
- SqlClientPermission.cs
- FrameDimension.cs
- ActivityExecutorSurrogate.cs
- FixedPosition.cs
- CodeTypeDeclarationCollection.cs
- ParameterEditorUserControl.cs
- Menu.cs
- AppDomainAttributes.cs
- TextTreeTextElementNode.cs
- BindableTemplateBuilder.cs
- TriggerBase.cs
- BackStopAuthenticationModule.cs
- SqlClientMetaDataCollectionNames.cs
- TypeConverterHelper.cs
- SQLBoolean.cs
- URLMembershipCondition.cs
- SectionXmlInfo.cs
- AttributeProviderAttribute.cs
- TextAutomationPeer.cs
- _OverlappedAsyncResult.cs
- BindingCollection.cs
- CodeRemoveEventStatement.cs
- GenerateTemporaryTargetAssembly.cs
- ExpressionEditorAttribute.cs
- ToolStripArrowRenderEventArgs.cs
- Action.cs
- JsonWriterDelegator.cs
- RequestCachePolicyConverter.cs
- DesignUtil.cs
- DesignTimeTemplateParser.cs
- DetailsViewUpdateEventArgs.cs
- OperationAbortedException.cs
- HttpDictionary.cs
- CodeTypeDeclaration.cs
- ManualWorkflowSchedulerService.cs
- ManagedWndProcTracker.cs
- Bitmap.cs
- EndOfStreamException.cs
- SessionSwitchEventArgs.cs
- SafeCoTaskMem.cs
- StreamResourceInfo.cs
- SiteMapNodeCollection.cs
- ReverseInheritProperty.cs
- SolidColorBrush.cs
- Rect.cs
- NamedPipeConnectionPoolSettings.cs
- WindowsBrush.cs
- SessionParameter.cs
- ProxyAttribute.cs
- MobileComponentEditorPage.cs
- TokenBasedSetEnumerator.cs
- TextTreeTextElementNode.cs
- Resources.Designer.cs
- _TransmitFileOverlappedAsyncResult.cs
- InstallerTypeAttribute.cs
- AssociatedControlConverter.cs
- HostingEnvironmentWrapper.cs
- SchemaCollectionCompiler.cs