/// <summary> /// Creates a collection of <see cref="ISyndicationExtension"/> instances for the specified types. /// </summary> /// <param name="types">A <see cref="Collection{T}"/> collection of <see cref="Type"/> objects that represent user-defined syndication extensions to be instantiated.</param> /// <param name="namespaces">A collection of XML nameapces that are used to filter the available native framework syndication extensions.</param> /// <returns> /// A <see cref="Collection{T}"/> collection of <see cref="ISyndicationExtension"/> objects instantiated using the supplied <paramref name="types"/> and <paramref name="namespaces"/>. /// </returns> /// <remarks> /// This method instantiates all of the available native framework syndication extensions, and then filters them based on the XML namespaces and prefixes contained in the supplied <paramref name="namespaces"/>. /// The user defined syndication extensions are then instantiated, and are added to the return collection if they do not already exist. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="types"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="namespaces"/> is a null reference (Nothing in Visual Basic).</exception> public static Collection <ISyndicationExtension> GetExtensions(Collection <Type> types, IEnumerable <KeyValuePair <string, string> > namespaces) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ Collection <ISyndicationExtension> supportedExtensions = new Collection <ISyndicationExtension>(); //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(types, "types"); Guard.ArgumentNotNull(namespaces, "namespaces"); //------------------------------------------------------------ // Add native framework extensions based on XML namespaces //------------------------------------------------------------ Collection <ISyndicationExtension> nativeExtensions = SyndicationExtensionAdapter.GetExtensions(SyndicationExtensionAdapter.FrameworkExtensions); foreach (ISyndicationExtension extension in nativeExtensions) { //BEGIN PATCH //if (namespaces.ContainsValue(extension.XmlNamespace) || namespaces.ContainsKey(extension.XmlPrefix)) if (namespaces.Any(item => item.Value == extension.XmlNamespace) || namespaces.Any(item => item.Key == extension.XmlPrefix)) //END PATCH { if (!supportedExtensions.Contains(extension)) { supportedExtensions.Add(extension); } } } //------------------------------------------------------------ // Add user defined extensions if not already in collection //------------------------------------------------------------ Collection <ISyndicationExtension> userExtensions = SyndicationExtensionAdapter.GetExtensions(types); foreach (ISyndicationExtension extension in userExtensions) { if (!supportedExtensions.Contains(extension)) { supportedExtensions.Add(extension); } } return(supportedExtensions); }
/// <summary> /// Modifies the <see cref="IExtensibleSyndicationObject"/> to match the data source. /// </summary> /// <param name="entity">The <see cref="IExtensibleSyndicationObject"/> to be filled.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve prefixed syndication elements and attributes.</param> /// <exception cref="ArgumentNullException">The <paramref name="entity"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(IExtensibleSyndicationObject entity, XmlNamespaceManager manager) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ Collection <ISyndicationExtension> extensions = new Collection <ISyndicationExtension>(); //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(entity, "entity"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Get syndication extensions supported by the load operation //------------------------------------------------------------ if (this.Settings.AutoDetectExtensions) { //BEGIN PATCH //extensions = SyndicationExtensionAdapter.GetExtensions(this.Settings.SupportedExtensions, (Dictionary<string, string>)this.Navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml)); extensions = SyndicationExtensionAdapter.GetExtensions(this.Settings.SupportedExtensions, this.Navigator.GetAllNamespaces()); //END PATCH } else { extensions = SyndicationExtensionAdapter.GetExtensions(this.Settings.SupportedExtensions); } //------------------------------------------------------------ // Add syndication extensions to entity if they exist in source //------------------------------------------------------------ foreach (ISyndicationExtension extension in extensions) { if (extension.ExistsInSource(this.Navigator)) { ISyndicationExtension instance = (ISyndicationExtension)Activator.CreateInstance(extension.GetType()); if (instance.Load(this.Navigator)) { ((Collection <ISyndicationExtension>)entity.Extensions).Add(instance); } } } }