/// <summary> /// Loads this <see cref="FeedHistoryLinkRelation"/> 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="FeedHistoryLinkRelation"/> 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="FeedHistoryLinkRelation"/>. /// </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 hrefAttribute = source.GetAttribute("href", String.Empty); string relAttribute = source.GetAttribute("rel", String.Empty); if (!String.IsNullOrEmpty(hrefAttribute)) { Uri href; if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out href)) { this.Uri = href; wasLoaded = true; } } if (!String.IsNullOrEmpty(relAttribute)) { FeedHistoryLinkRelationType relationType = FeedHistorySyndicationExtension.LinkRelationTypeByName(relAttribute); if (relationType != FeedHistoryLinkRelationType.None) { this.RelationType = relationType; wasLoaded = true; } } } return(wasLoaded); }
/// <summary> /// Returns the <see cref="FeedHistoryLinkRelationType"/> enumeration value that corresponds to the specified link relation. /// </summary> /// <param name="name">The name of the link relation.</param> /// <returns>A <see cref="FeedHistoryLinkRelationType"/> enumeration value that corresponds to the specified string, otherwise returns <b>FeedHistoryLinkRelationType.None</b>.</returns> /// <remarks>This method disregards case of specified link relation 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 FeedHistoryLinkRelationType LinkRelationTypeByName(string name) { FeedHistoryLinkRelationType relationType = FeedHistoryLinkRelationType.None; Guard.ArgumentNotNullOrEmptyString(name, "name"); foreach (System.Reflection.FieldInfo fieldInfo in typeof(FeedHistoryLinkRelationType).GetFields()) { if (fieldInfo.FieldType == typeof(FeedHistoryLinkRelationType)) { FeedHistoryLinkRelationType relation = (FeedHistoryLinkRelationType)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) { relationType = relation; break; } } } } return(relationType); }
/// <summary> /// Returns the link relation identifier for the supplied <see cref="FeedHistoryLinkRelationType"/>. /// </summary> /// <param name="relation">The <see cref="FeedHistoryLinkRelationType"/> to get the link relation identifier for.</param> /// <returns>The link relation identifier for the supplied <paramref name="relation"/>, otherwise returns an empty string.</returns> public static string LinkRelationTypeAsString(FeedHistoryLinkRelationType relation) { string name = String.Empty; foreach (System.Reflection.FieldInfo fieldInfo in typeof(FeedHistoryLinkRelationType).GetFields()) { if (fieldInfo.FieldType == typeof(FeedHistoryLinkRelationType)) { FeedHistoryLinkRelationType relationType = (FeedHistoryLinkRelationType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (relationType == relation) { 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> /// Initializes a new instance of the <see cref="FeedHistoryLinkRelation"/> class using the supplied relation type and location. /// </summary> /// <param name="relation">A <see cref="FeedHistoryLinkRelationType"/> enumeration value that indicates the link relation type.</param> /// <param name="href">A <see cref="Uri"/> that represents the location this link relation points to.</param> /// <exception cref="ArgumentNullException">The <paramref name="href"/> is a null reference (Nothing in Visual Basic).</exception> public FeedHistoryLinkRelation(FeedHistoryLinkRelationType relation, Uri href) { //------------------------------------------------------------ // Initialize class state using guarded properties //------------------------------------------------------------ this.RelationType = relation; this.Uri = href; }
/// <summary> /// Returns the link relation identifier for the supplied <see cref="FeedHistoryLinkRelationType"/>. /// </summary> /// <param name="relation">The <see cref="FeedHistoryLinkRelationType"/> to get the link relation identifier for.</param> /// <returns>The link relation identifier for the supplied <paramref name="relation"/>, otherwise returns an empty string.</returns> public static string LinkRelationTypeAsString(FeedHistoryLinkRelationType relation) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(FeedHistoryLinkRelationType).GetFields()) { if (fieldInfo.FieldType == typeof(FeedHistoryLinkRelationType)) { FeedHistoryLinkRelationType relationType = (FeedHistoryLinkRelationType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (relationType == relation) { 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> /// Initializes a new instance of the <see cref="FeedHistoryLinkRelation"/> class using the supplied relation type and location. /// </summary> /// <param name="relation">A <see cref="FeedHistoryLinkRelationType"/> enumeration value that indicates the link relation type.</param> /// <param name="href">A <see cref="Uri"/> that represents the location this link relation points to.</param> /// <exception cref="ArgumentNullException">The <paramref name="href"/> is a null reference (Nothing in Visual Basic).</exception> public FeedHistoryLinkRelation(FeedHistoryLinkRelationType relation, Uri href) { this.RelationType = relation; this.Uri = href; }