/// <summary> /// Loads this <see cref="YahooMediaTextConstruct"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="YahooMediaTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="YahooMediaTextConstruct"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { YahooMediaTextConstructType type = YahooMediaTextConstruct.TextTypeByName(typeAttribute); if (type != YahooMediaTextConstructType.None) { this.TextType = type; wasLoaded = true; } } } if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return(wasLoaded); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="YahooMediaTextConstruct"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="YahooMediaTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="YahooMediaTextConstruct"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { YahooMediaTextConstructType type = YahooMediaTextConstruct.TextTypeByName(typeAttribute); if (type != YahooMediaTextConstructType.None) { this.TextType = type; wasLoaded = true; } } } if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return(wasLoaded); }
/// <summary> /// Loads this <see cref="YahooMediaText"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="YahooMediaText"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="YahooMediaText"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); string languageAttribute = source.GetAttribute("lang", String.Empty); string startAttribute = source.GetAttribute("start", String.Empty); string endAttribute = source.GetAttribute("end", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { YahooMediaTextConstructType type = YahooMediaTextConstruct.TextTypeByName(typeAttribute); if (type != YahooMediaTextConstructType.None) { this.TextType = type; wasLoaded = true; } } if (!String.IsNullOrEmpty(languageAttribute)) { try { CultureInfo language = new CultureInfo(languageAttribute); this.Language = language; wasLoaded = true; } catch (ArgumentException) { System.Diagnostics.Trace.TraceWarning("YahooMediaText was unable to determine CultureInfo with a name of {0}.", languageAttribute); } } if (!String.IsNullOrEmpty(startAttribute)) { TimeSpan start; if (TimeSpan.TryParse(startAttribute, out start)) { this.Start = start; wasLoaded = true; } } if (!String.IsNullOrEmpty(endAttribute)) { TimeSpan end; if (TimeSpan.TryParse(endAttribute, out end)) { this.End = end; wasLoaded = true; } } } if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return(wasLoaded); }