Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Syndication / SyndicationElementExtensionCollection.cs / 1 / SyndicationElementExtensionCollection.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Syndication { using System.Collections; using System.Collections.ObjectModel; using System.Runtime.Serialization; using System.Xml; using System.Xml.Serialization; using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System.ServiceModel.Web; // sealed because the ctor results in a call to the virtual InsertItem method public sealed class SyndicationElementExtensionCollection : Collection{ XmlBuffer buffer; bool initialized; internal SyndicationElementExtensionCollection() : this((XmlBuffer) null) { } internal SyndicationElementExtensionCollection(XmlBuffer buffer) : base() { this.buffer = buffer; if (this.buffer != null) { PopulateElements(); } initialized = true; } internal SyndicationElementExtensionCollection(SyndicationElementExtensionCollection source) : base() { this.buffer = source.buffer; for (int i = 0; i < source.Items.Count; ++i) { base.Add(source.Items[i]); } initialized = true; } public void Add(object extension) { if (extension is SyndicationElementExtension) { base.Add((SyndicationElementExtension) extension); } else { this.Add(extension, (DataContractSerializer) null); } } public void Add(string outerName, string outerNamespace, object dataContractExtension) { this.Add(outerName, outerNamespace, dataContractExtension, null); } public void Add(object dataContractExtension, DataContractSerializer serializer) { this.Add(null, null, dataContractExtension, serializer); } public void Add(string outerName, string outerNamespace, object dataContractExtension, XmlObjectSerializer dataContractSerializer) { if (dataContractExtension == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dataContractExtension"); } if (dataContractSerializer == null) { dataContractSerializer = new DataContractSerializer(dataContractExtension.GetType()); } base.Add(new SyndicationElementExtension(outerName, outerNamespace, dataContractExtension, dataContractSerializer)); } public void Add(object xmlSerializerExtension, XmlSerializer serializer) { if (xmlSerializerExtension == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlSerializerExtension"); } if (serializer == null) { serializer = new XmlSerializer(xmlSerializerExtension.GetType()); } base.Add(new SyndicationElementExtension(xmlSerializerExtension, serializer)); } public void Add(XmlReader xmlReader) { if (xmlReader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlReader"); } base.Add(new SyndicationElementExtension(xmlReader)); } public XmlReader GetReaderAtElementExtensions() { XmlBuffer extensionsBuffer = GetOrCreateBufferOverExtensions(); XmlReader reader = extensionsBuffer.GetReader(0); reader.ReadStartElement(); return reader; } public Collection ReadElementExtensions (string extensionName, string extensionNamespace) { return ReadElementExtensions (extensionName, extensionNamespace, new DataContractSerializer(typeof(TExtension))); } public Collection ReadElementExtensions (string extensionName, string extensionNamespace, XmlObjectSerializer serializer) { if (serializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serializer"); } return ReadExtensions (extensionName, extensionNamespace, serializer, null); } public Collection ReadElementExtensions (string extensionName, string extensionNamespace, XmlSerializer serializer) { if (serializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serializer"); } return ReadExtensions (extensionName, extensionNamespace, null, serializer); } internal void WriteTo(XmlWriter writer) { if (this.buffer != null) { using (XmlDictionaryReader reader = this.buffer.GetReader(0)) { reader.ReadStartElement(); while (reader.IsStartElement()) { writer.WriteNode(reader, false); } } } else { for (int i = 0; i < this.Items.Count; ++i) { this.Items[i].WriteTo(writer); } } } protected override void ClearItems() { base.ClearItems(); // clear the cached buffer if the operation is happening outside the constructor if (initialized) { this.buffer = null; } } protected override void InsertItem(int index, SyndicationElementExtension item) { if (item == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("item"); } base.InsertItem(index, item); // clear the cached buffer if the operation is happening outside the constructor if (initialized) { this.buffer = null; } } protected override void RemoveItem(int index) { base.RemoveItem(index); // clear the cached buffer if the operation is happening outside the constructor if (initialized) { this.buffer = null; } } protected override void SetItem(int index, SyndicationElementExtension item) { if (item == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("item"); } base.SetItem(index, item); // clear the cached buffer if the operation is happening outside the constructor if (initialized) { this.buffer = null; } } XmlBuffer GetOrCreateBufferOverExtensions() { if (this.buffer != null) { return this.buffer; } XmlBuffer newBuffer = new XmlBuffer(int.MaxValue); using (XmlWriter writer = newBuffer.OpenSection(XmlDictionaryReaderQuotas.Max)) { writer.WriteStartElement(Rss20Constants.ExtensionWrapperTag); for (int i = 0; i < this.Count; ++i) { this[i].WriteTo(writer); } writer.WriteEndElement(); } newBuffer.CloseSection(); newBuffer.Close(); this.buffer = newBuffer; return newBuffer; } void PopulateElements() { using (XmlDictionaryReader reader = this.buffer.GetReader(0)) { reader.ReadStartElement(); int index = 0; while (reader.IsStartElement()) { base.Add(new SyndicationElementExtension(this.buffer, index, reader.LocalName, reader.NamespaceURI)); reader.Skip(); ++index; } } } Collection ReadExtensions (string extensionName, string extensionNamespace, XmlObjectSerializer dcSerializer, XmlSerializer xmlSerializer) { if (string.IsNullOrEmpty(extensionName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR2.GetString(SR2.ExtensionNameNotSpecified)); } Fx.Assert((dcSerializer == null) != (xmlSerializer == null), "exactly one serializer should be supplied"); // normalize the null and empty namespace if (extensionNamespace == null) { extensionNamespace = string.Empty; } Collection results = new Collection (); for (int i = 0; i < this.Count; ++i) { if (extensionName != this[i].OuterName || extensionNamespace != this[i].OuterNamespace) { continue; } if (dcSerializer != null) { results.Add(this[i].GetObject (dcSerializer)); } else { results.Add(this[i].GetObject (xmlSerializer)); } } return results; } } } // 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
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- PtsCache.cs
- TrustLevelCollection.cs
- ValidateNames.cs
- PathGradientBrush.cs
- SHA512Managed.cs
- StatusBarDrawItemEvent.cs
- WsdlBuildProvider.cs
- DataGridViewDataErrorEventArgs.cs
- Int32KeyFrameCollection.cs
- CollectionViewGroup.cs
- XPathAncestorIterator.cs
- WorkflowTransactionService.cs
- RunInstallerAttribute.cs
- PathFigure.cs
- InstanceCreationEditor.cs
- SystemIPv4InterfaceProperties.cs
- WizardStepBase.cs
- SolidColorBrush.cs
- UshortList2.cs
- FragmentNavigationEventArgs.cs
- BamlTreeNode.cs
- WebPartDescriptionCollection.cs
- EntityContainerAssociationSet.cs
- AbstractSvcMapFileLoader.cs
- LineBreakRecord.cs
- DetailsViewActionList.cs
- _ListenerResponseStream.cs
- PasswordDeriveBytes.cs
- FixedSchema.cs
- CodeCatchClauseCollection.cs
- StateWorkerRequest.cs
- DataSetMappper.cs
- EntityTransaction.cs
- RemotingConfiguration.cs
- X509ChainElement.cs
- OperationAbortedException.cs
- CodeTypeParameter.cs
- BindingListCollectionView.cs
- SqlServer2KCompatibilityCheck.cs
- Char.cs
- InvalidateEvent.cs
- LexicalChunk.cs
- EndOfStreamException.cs
- EmbeddedMailObjectsCollection.cs
- HtmlFormAdapter.cs
- EntityDataSourceChangedEventArgs.cs
- Group.cs
- RegexCompiler.cs
- SourceInterpreter.cs
- WbemProvider.cs
- FocusTracker.cs
- externdll.cs
- CodeDelegateCreateExpression.cs
- XmlUtil.cs
- OperatorExpressions.cs
- EmptyImpersonationContext.cs
- DelegatedStream.cs
- DrawingContextDrawingContextWalker.cs
- UdpDiscoveryEndpointProvider.cs
- ObjectParameter.cs
- RepeatButtonAutomationPeer.cs
- StorageAssociationTypeMapping.cs
- AssociationSetEnd.cs
- DataSourceSelectArguments.cs
- TextServicesDisplayAttributePropertyRanges.cs
- OperationContractGenerationContext.cs
- ScrollEventArgs.cs
- HostedNamedPipeTransportManager.cs
- uribuilder.cs
- CodeAccessSecurityEngine.cs
- FilteredDataSetHelper.cs
- ClickablePoint.cs
- TypeInfo.cs
- TimerEventSubscriptionCollection.cs
- DefaultValueAttribute.cs
- ObjectDataSourceEventArgs.cs
- BaseValidator.cs
- Triangle.cs
- BaseProcessProtocolHandler.cs
- QueryTask.cs
- SimpleTypesSurrogate.cs
- httpapplicationstate.cs
- ToolStripMenuItem.cs
- Material.cs
- ObsoleteAttribute.cs
- LockCookie.cs
- FramingDecoders.cs
- DataKeyCollection.cs
- Opcode.cs
- TraceLevelHelper.cs
- HyperLink.cs
- HttpListenerTimeoutManager.cs
- AdRotator.cs
- SelfIssuedSamlTokenFactory.cs
- HttpRequest.cs
- EntityKey.cs
- EventProxy.cs
- unsafenativemethodsother.cs
- Viewport2DVisual3D.cs