/// <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); }
/// <summary> /// Returns the entity encoding type identifier for the supplied <see cref="YahooMediaTextConstructType"/>. /// </summary> /// <param name="type">The <see cref="YahooMediaTextConstructType"/> to get the entity encoding type identifier for.</param> /// <returns>The entity encoding type identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns> public static string TextTypeAsString(YahooMediaTextConstructType type) { string name = String.Empty; foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaTextConstructType).GetFields()) { if (fieldInfo.FieldType == typeof(YahooMediaTextConstructType)) { YahooMediaTextConstructType constructType = (YahooMediaTextConstructType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (constructType == type) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; name = enumerationMetadata.AlternateValue; break; } } } } return(name); }
/// <summary> /// Returns the <see cref="YahooMediaTextConstructType"/> enumeration value that corresponds to the specified entity encoding type name. /// </summary> /// <param name="name">The name of the entity encoding type.</param> /// <returns>A <see cref="YahooMediaTextConstructType"/> enumeration value that corresponds to the specified string, otherwise returns <b>YahooMediaTextConstructType.None</b>.</returns> /// <remarks>This method disregards case of specified entity encoding type name.</remarks> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception> public static YahooMediaTextConstructType TextTypeByName(string name) { YahooMediaTextConstructType constructType = YahooMediaTextConstructType.None; Guard.ArgumentNotNullOrEmptyString(name, "name"); foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaTextConstructType).GetFields()) { if (fieldInfo.FieldType == typeof(YahooMediaTextConstructType)) { YahooMediaTextConstructType type = (YahooMediaTextConstructType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0) { constructType = type; break; } } } } return(constructType); }
/// <summary> /// Initializes a new instance of the <see cref="YahooMediaTextConstruct"/> class using the supplied text. /// </summary> /// <param name="text">The content of this human-readable text.</param> /// <param name="type">An <see cref="YahooMediaTextConstruct"/> enumeration value that represents the entity encoding utilized by this human-readable text.</param> /// <exception cref="ArgumentNullException">The <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="text"/> is an empty string.</exception> public YahooMediaTextConstruct(string text, YahooMediaTextConstructType type) : this(text) { //------------------------------------------------------------ // Initialize class state using guarded properties //------------------------------------------------------------ this.TextType = type; }
//============================================================ // 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> /// Initializes a new instance of the <see cref="YahooMediaTextConstruct"/> class using the supplied text. /// </summary> /// <param name="text">The content of this human-readable text.</param> /// <param name="type">An <see cref="YahooMediaTextConstruct"/> enumeration value that represents the entity encoding utilized by this human-readable text.</param> /// <exception cref="ArgumentNullException">The <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="text"/> is an empty string.</exception> public YahooMediaTextConstruct(string text, YahooMediaTextConstructType type) : this(text) { this.TextType = type; }
/// <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) { //------------------------------------------------------------ // 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); 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; }
/// <summary> /// Returns the entity encoding type identifier for the supplied <see cref="YahooMediaTextConstructType"/>. /// </summary> /// <param name="type">The <see cref="YahooMediaTextConstructType"/> to get the entity encoding type identifier for.</param> /// <returns>The entity encoding type identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns> public static string TextTypeAsString(YahooMediaTextConstructType type) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaTextConstructType).GetFields()) { if (fieldInfo.FieldType == typeof(YahooMediaTextConstructType)) { YahooMediaTextConstructType constructType = (YahooMediaTextConstructType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (constructType == type) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; name = enumerationMetadata.AlternateValue; break; } } } } return name; }
/// <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); }