Remove dead code from Syndication
authorHugh Bellamy <hughbellars@gmail.com>
Wed, 13 Jun 2018 17:14:18 +0000 (18:14 +0100)
committerMatt Connew <mconnew@microsoft.com>
Thu, 16 Aug 2018 18:22:05 +0000 (11:22 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/628edf4dd6552be37942f937d16b73a37f305f2f

13 files changed:
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Atom10FeedFormatter.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatter.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/AtomPub10ServiceDocumentFormatter.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Rss20FeedFormatter.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ServiceDocumentFormatter.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationContent.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationElementExtension.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationElementExtensionCollection.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationFeed.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationFeedFormatter.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/TextSyndicationContent.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/UrlSyndicationContent.cs
src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/XmlSyndicationContent.cs

index 79689fe..d009873 100644 (file)
@@ -14,22 +14,6 @@ using System.Diagnostics;
 
 namespace System.ServiceModel.Syndication
 {
-<<<<<<< HEAD
-    using System;
-    using System.Collections.Generic;
-    using System.Collections.ObjectModel;
-    using System.Globalization;
-    using System.Text;
-    using System.Xml;
-    using System.Xml.Serialization;
-    using System.Diagnostics.CodeAnalysis;
-    using System.Xml.Schema;
-    using System.Collections;
-    using System.ServiceModel.Channels;
-    using System.Runtime.CompilerServices;
-
-=======
->>>>>>> Misc cleanup in Syndication
     [XmlRoot(ElementName = Atom10Constants.FeedTag, Namespace = Atom10Constants.Atom10Namespace)]
     public class Atom10FeedFormatter : SyndicationFeedFormatter, IXmlSerializable
     {
@@ -627,10 +611,8 @@ namespace System.ServiceModel.Syndication
             {
                 foreach (XmlQualifiedName attr in attrs.Keys)
                 {
-                    if (!FeedUtils.IsXmlns(attr.Name, attr.Namespace))
-                    {
-                        result.AttributeExtensions.Add(attr, attrs[attr]);
-                    }
+                    Debug.Assert(!FeedUtils.IsXmlns(attr.Name, attr.Namespace), "XML namespace attributes should not be added to the list." );
+                    result.AttributeExtensions.Add(attr, attrs[attr]);
                 }
             }
             return result;
index cef9dae..ea93959 100644 (file)
@@ -160,8 +160,6 @@ namespace System.ServiceModel.Syndication
             {
                 SyndicationFeedFormatter.MoveToStartElement(reader);
                 SetDocument(AtomPub10ServiceDocumentFormatter.ReadCategories(reader, null,
-                    _preserveElementExtensions,
-                    _preserveAttributeExtensions,
                     () => CreateInlineCategoriesDocument(),
                     () => CreateReferencedCategoriesDocument(),
                     Version,
index 6859a03..c05e11c 100644 (file)
@@ -16,8 +16,6 @@ namespace System.ServiceModel.Syndication
     [XmlRoot(ElementName = App10Constants.Service, Namespace = App10Constants.Namespace)]
     public class AtomPub10ServiceDocumentFormatter : ServiceDocumentFormatter, IXmlSerializable
     {
-        private bool _preserveAttributeExtensions;
-        private bool _preserveElementExtensions;
         private readonly Type _documentType;
         private readonly int _maxExtensionSize;
 
@@ -37,16 +35,12 @@ namespace System.ServiceModel.Syndication
             }
 
             _maxExtensionSize = int.MaxValue;
-            _preserveAttributeExtensions = true;
-            _preserveElementExtensions = true;
             _documentType = documentTypeToCreate;
         }
 
         public AtomPub10ServiceDocumentFormatter(ServiceDocument documentToWrite) : base(documentToWrite)
         {
             _maxExtensionSize = int.MaxValue;
-            _preserveAttributeExtensions = true;
-            _preserveElementExtensions = true;
             _documentType = documentToWrite.GetType();
         }
 
@@ -123,19 +117,19 @@ namespace System.ServiceModel.Syndication
             writer.WriteEndElement();
         }
 
-        internal static CategoriesDocument ReadCategories(XmlReader reader, Uri baseUri, CreateInlineCategoriesDelegate inlineCategoriesFactory, CreateReferencedCategoriesDelegate referencedCategoriesFactory, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
+        internal static CategoriesDocument ReadCategories(XmlReader reader, Uri baseUri, CreateInlineCategoriesDelegate inlineCategoriesFactory, CreateReferencedCategoriesDelegate referencedCategoriesFactory, string version, int maxExtensionSize)
         {
             string link = reader.GetAttribute(App10Constants.Href, string.Empty);
             if (string.IsNullOrEmpty(link))
             {
                 InlineCategoriesDocument inlineCategories = inlineCategoriesFactory();
-                ReadInlineCategories(reader, inlineCategories, baseUri, version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize);
+                ReadInlineCategories(reader, inlineCategories, baseUri, version, maxExtensionSize);
                 return inlineCategories;
             }
             else
             {
                 ReferencedCategoriesDocument referencedCategories = referencedCategoriesFactory();
-                ReadReferencedCategories(reader, referencedCategories, baseUri, new Uri(link, UriKind.RelativeOrAbsolute), version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize);
+                ReadReferencedCategories(reader, referencedCategories, baseUri, new Uri(link, UriKind.RelativeOrAbsolute), version, maxExtensionSize);
                 return referencedCategories;
             }
         }
@@ -173,7 +167,7 @@ namespace System.ServiceModel.Syndication
             }
         }
 
-        private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
+        private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, int maxExtensionSize)
         {
             inlineCategories.BaseUri = baseUri;
             if (reader.HasAttributes)
@@ -208,10 +202,7 @@ namespace System.ServiceModel.Syndication
                         string val = reader.Value;
                         if (!TryParseAttribute(name, ns, val, inlineCategories, version))
                         {
-                            if (preserveAttributeExtensions)
-                            {
-                                inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
-                            }
+                            inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                         }
                     }
                 }
@@ -230,7 +221,7 @@ namespace System.ServiceModel.Syndication
                         if (reader.IsStartElement(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace))
                         {
                             SyndicationCategory category = CreateCategory(inlineCategories);
-                            Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, maxExtensionSize);
+                            Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions: true, preserveElementExtensions: true, maxExtensionSize);
                             if (category.Scheme == null)
                             {
                                 category.Scheme = inlineCategories.Scheme;
@@ -239,10 +230,7 @@ namespace System.ServiceModel.Syndication
                         }
                         else if (!TryParseElement(reader, inlineCategories, version))
                         {
-                            if (preserveElementExtensions)
-                            {
-                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
-                            }
+                            SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
                         }
                     }
                     LoadElementExtensions(buffer, extWriter, inlineCategories);
@@ -255,7 +243,7 @@ namespace System.ServiceModel.Syndication
             }
         }
 
-        private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
+        private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, int maxExtensionSize)
         {
             referencedCategories.BaseUri = baseUri;
             referencedCategories.Link = link;
@@ -287,10 +275,7 @@ namespace System.ServiceModel.Syndication
                         string val = reader.Value;
                         if (!TryParseAttribute(name, ns, val, referencedCategories, version))
                         {
-                            if (preserveAttributeExtensions)
-                            {
-                                referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
-                            }
+                            referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                         }
                     }
                 }
@@ -309,10 +294,7 @@ namespace System.ServiceModel.Syndication
                     {
                         if (!TryParseElement(reader, referencedCategories, version))
                         {
-                            if (preserveElementExtensions)
-                            {
-                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
-                            }
+                            SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
                         }
                     }
                     LoadElementExtensions(buffer, extWriter, referencedCategories);
@@ -399,10 +381,7 @@ namespace System.ServiceModel.Syndication
                         string val = reader.Value;
                         if (!TryParseAttribute(name, ns, val, result, Version))
                         {
-                            if (_preserveAttributeExtensions)
-                            {
-                                result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
-                            }
+                            result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                         }
                     }
                 }
@@ -418,14 +397,12 @@ namespace System.ServiceModel.Syndication
                 {
                     if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
                     {
-                        result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", _preserveAttributeExtensions);
+                        result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", preserveAttributeExtensions: true);
                     }
                     else if (reader.IsStartElement(App10Constants.Categories, App10Constants.Namespace))
                     {
                         result.Categories.Add(ReadCategories(reader,
                             result.BaseUri,
-                            _preserveElementExtensions,
-                            _preserveAttributeExtensions,
                             () => CreateInlineCategories(result),
                             () => CreateReferencedCategories(result),
                             Version,
@@ -437,10 +414,7 @@ namespace System.ServiceModel.Syndication
                     }
                     else if (!TryParseElement(reader, result, Version))
                     {
-                        if (_preserveElementExtensions)
-                        {
-                            SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
-                        }
+                        SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
                     }
                 }
                 LoadElementExtensions(buffer, extWriter, result);
@@ -485,10 +459,7 @@ namespace System.ServiceModel.Syndication
                             string val = reader.Value;
                             if (!TryParseAttribute(name, ns, val, result, Version))
                             {
-                                if (_preserveAttributeExtensions)
-                                {
-                                    result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
-                                }
+                                result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                             }
                         }
                     }
@@ -509,10 +480,7 @@ namespace System.ServiceModel.Syndication
                             }
                             else if (!TryParseElement(reader, result, Version))
                             {
-                                if (_preserveElementExtensions)
-                                {
-                                    SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
-                                }
+                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
                             }
                         }
                         LoadElementExtensions(buffer, extWriter, result);
index 78d07b0..8df5705 100644 (file)
@@ -14,21 +14,6 @@ using System.Xml.Serialization;
 
 namespace System.ServiceModel.Syndication
 {
-<<<<<<< HEAD
-    using System;
-    using System.Collections.Generic;
-    using System.Diagnostics;
-    using System.Diagnostics.CodeAnalysis;
-    using System.Globalization;
-    using System.Runtime;
-    using System.Text;
-    using System.Xml;
-    using System.Xml.Schema;
-    using System.Xml.Serialization;
-    using System.Runtime.CompilerServices;
-
-=======
->>>>>>> Misc cleanup in Syndication
     [XmlRoot(ElementName = Rss20Constants.RssTag, Namespace = Rss20Constants.Rss20Namespace)]
     public class Rss20FeedFormatter : SyndicationFeedFormatter, IXmlSerializable
     {
index f12ba66..9c62dae 100644 (file)
@@ -32,10 +32,7 @@ namespace System.ServiceModel.Syndication
 
         internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, CategoriesDocument categories)
         {
-            if (categories == null)
-            {
-                throw new ArgumentNullException(nameof(categories));
-            }
+            Debug.Assert(categories != null);
 
             SyndicationFeedFormatter.CloseBuffer(buffer, writer);
             categories.LoadElementExtensions(buffer);
@@ -43,10 +40,7 @@ namespace System.ServiceModel.Syndication
 
         internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, ResourceCollectionInfo collection)
         {
-            if (collection == null)
-            {
-                throw new ArgumentNullException(nameof(collection));
-            }
+            Debug.Assert(collection != null);
 
             SyndicationFeedFormatter.CloseBuffer(buffer, writer);
             collection.LoadElementExtensions(buffer);
@@ -54,10 +48,7 @@ namespace System.ServiceModel.Syndication
 
         internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, Workspace workspace)
         {
-            if (workspace == null)
-            {
-                throw new ArgumentNullException(nameof(workspace));
-            }
+            Debug.Assert(workspace != null);
 
             SyndicationFeedFormatter.CloseBuffer(buffer, writer);
             workspace.LoadElementExtensions(buffer);
index 5eff392..c422712 100644 (file)
@@ -89,11 +89,8 @@ namespace System.ServiceModel.Syndication
                     {
                         continue;
                     }
-                    string attrValue;
-                    if (_attributeExtensions.TryGetValue(key, out attrValue))
-                    {
-                        writer.WriteAttributeString(key.Name, key.Namespace, attrValue);
-                    }
+
+                    writer.WriteAttributeString(key.Name, key.Namespace, _attributeExtensions[key]);
                 }
             }
             WriteContentsTo(writer);
index b23c5cf..76923f5 100644 (file)
@@ -273,13 +273,8 @@ namespace System.ServiceModel.Syndication
 
             internal void ComputeOuterNameAndNs(out string name, out string ns)
             {
-                if (_outerName != null)
-                {
-                    Debug.Assert(_xmlSerializer == null, "outer name is not null for data contract extension only");
-                    name = _outerName;
-                    ns = _outerNamespace;
-                }
-                else if (_dataContractSerializer != null)
+                Debug.Assert(_outerName == null, "All callers of this function should already check for a null outer name.");
+                if (_dataContractSerializer != null)
                 {
                     Debug.Assert(_xmlSerializer == null, "only one of xmlserializer or datacontract serializer can be present");
                     XsdDataContractExporter dcExporter = new XsdDataContractExporter();
index 34125be..37de723 100644 (file)
@@ -164,11 +164,9 @@ namespace System.ServiceModel.Syndication
         protected override void ClearItems()
         {
             base.ClearItems();
-            // clear the cached buffer if the operation is happening outside the constructor
-            if (_initialized)
-            {
-                _buffer = null;
-            }
+
+            Debug.Assert(_initialized, "The constructor should never clear the collection.");
+            _buffer = null;
         }
 
         protected override void InsertItem(int index, SyndicationElementExtension item)
@@ -189,11 +187,9 @@ namespace System.ServiceModel.Syndication
         protected override void RemoveItem(int index)
         {
             base.RemoveItem(index);
-            // clear the cached buffer if the operation is happening outside the constructor
-            if (_initialized)
-            {
-                _buffer = null;
-            }
+
+            Debug.Assert(_initialized, "The constructor should never remove items from the collection.");
+            _buffer = null;
         }
 
         protected override void SetItem(int index, SyndicationElementExtension item)
@@ -204,11 +200,8 @@ namespace System.ServiceModel.Syndication
             }
 
             base.SetItem(index, item);
-            // clear the cached buffer if the operation is happening outside the constructor
-            if (_initialized)
-            {
-                _buffer = null;
-            }
+            Debug.Assert(_initialized, "The constructor should never set items in the collection.");
+            _buffer = null;
         }
 
         private XmlBuffer GetOrCreateBufferOverExtensions()
index 21b6f74..37b13ca 100644 (file)
@@ -435,18 +435,13 @@ namespace System.ServiceModel.Syndication
             }
 
             throw new XmlException(SR.Format(SR.UnknownFeedXml, reader.LocalName, reader.NamespaceURI));
-<<<<<<< HEAD
         }
 
         public virtual SyndicationFeed Clone(bool cloneItems)
         {
             return new SyndicationFeed(this, cloneItems);
-=======
->>>>>>> Misc cleanup in Syndication
         }
 
-        public virtual SyndicationFeed Clone(bool cloneItems) => new SyndicationFeed(this, cloneItems);
-
         public Atom10FeedFormatter GetAtom10Formatter() => new Atom10FeedFormatter(this);
 
         public Rss20FeedFormatter GetRss20Formatter() => GetRss20Formatter(true);
index aa0d86e..bdb63a1 100644 (file)
@@ -9,15 +9,6 @@ using System.Xml;
 
 namespace System.ServiceModel.Syndication
 {
-<<<<<<< HEAD
-    using System;
-    using System.Diagnostics;
-    using System.Globalization;
-    using System.Runtime.Serialization;
-    using System.Xml;
-
-=======
->>>>>>> Misc cleanup in Syndication
     public delegate bool TryParseDateTimeCallback(XmlDateTimeData data, out DateTimeOffset dateTimeOffset);
     public delegate bool TryParseUriCallback(XmlUriData data, out Uri uri);
 
@@ -522,10 +513,7 @@ namespace System.ServiceModel.Syndication
 
         internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationItem item)
         {
-            if (item == null)
-            {
-                throw new ArgumentNullException(nameof(item));
-            }
+            Debug.Assert(item != null);
 
             CloseBuffer(buffer, writer);
             item.LoadElementExtensions(buffer);
@@ -533,10 +521,7 @@ namespace System.ServiceModel.Syndication
 
         internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
         {
-            if (category == null)
-            {
-                throw new ArgumentNullException(nameof(category));
-            }
+            Debug.Assert(category != null);
 
             CloseBuffer(buffer, writer);
             category.LoadElementExtensions(buffer);
@@ -544,10 +529,7 @@ namespace System.ServiceModel.Syndication
 
         internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationLink link)
         {
-            if (link == null)
-            {
-                throw new ArgumentNullException(nameof(link));
-            }
+            Debug.Assert(link != null);
 
             CloseBuffer(buffer, writer);
             link.LoadElementExtensions(buffer);
@@ -555,10 +537,7 @@ namespace System.ServiceModel.Syndication
 
         internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationPerson person)
         {
-            if (person == null)
-            {
-                throw new ArgumentNullException(nameof(person));
-            }
+            Debug.Assert(person != null);
 
             CloseBuffer(buffer, writer);
             person.LoadElementExtensions(buffer);
index c054c97..4445b09 100644 (file)
@@ -29,11 +29,7 @@ namespace System.ServiceModel.Syndication
 
         protected TextSyndicationContent(TextSyndicationContent source) : base(source)
         {
-            if (source == null)
-            {
-                throw new ArgumentNullException(nameof(source));
-            }
-
+            Debug.Assert(source != null, "The base constructor already checks if source is valid.");
             Text = source.Text;
             _textKind = source._textKind;
         }
index 8be623f..10674cc 100644 (file)
@@ -20,11 +20,7 @@ namespace System.ServiceModel.Syndication
 
         protected UrlSyndicationContent(UrlSyndicationContent source) : base(source)
         {
-            if (source == null)
-            {
-                throw new ArgumentNullException(nameof(source));
-            }
-
+            Debug.Assert(source != null, "The base constructor already checks if source is valid.");
             Url = source.Url;
             _mediaType = source._mediaType;
         }
index 594fe29..a627583 100644 (file)
@@ -74,11 +74,7 @@ namespace System.ServiceModel.Syndication
 
         protected XmlSyndicationContent(XmlSyndicationContent source) : base(source)
         {
-            if (source == null)
-            {
-                throw new ArgumentNullException(nameof(source));
-            }
-
+            Debug.Assert(source != null, "The base constructor already checks if source is valid.");
             _contentBuffer = source._contentBuffer;
             Extension = source.Extension;
             _type = source._type;
@@ -154,8 +150,9 @@ namespace System.ServiceModel.Syndication
             {
                 Extension.WriteTo(writer);
             }
-            else if (_contentBuffer != null)
+            else
             {
+                Debug.Assert(_contentBuffer != null, "contentBuffer cannot be null");
                 using (XmlDictionaryReader reader = _contentBuffer.GetReader(0))
                 {
                     reader.MoveToStartElement();