Skip to content

Commit

Permalink
Added strongly types conveniences methods to AttributeDictionary
Browse files Browse the repository at this point in the history
To aid in retrieving strongly types values from the `AttributeDictionary`, I've added convenience methods for e.g. `GetBooleanValue()`, `GetInteger()`, &c., each corresponding to the convertible types on the `AttributeValueConverter`. This will make it easier to implement logic in view models. In addition, since `AttributeValueConverter` is currently `internal`, this allows external libraries—including `OnTopic.ViewModels`—to benefit from the the conversion logic without having to have direct access to the library.

This aids in the implementation of Feature #99.
  • Loading branch information
JeremyCaney committed Dec 21, 2021
1 parent 30bd3e5 commit 8e09fc5
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions OnTopic/Attributes/AttributeDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,60 @@ public AttributeDictionary(): base(StringComparer.OrdinalIgnoreCase) { }
return String.IsNullOrWhiteSpace(value)? null : value;
}

/*==========================================================================================================================
| METHOD: GET BOOLEAN VALUE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Gets an attribute value as a Boolean from the <see cref="AttributeDictionary"/> based on the <paramref name="
/// attributeKey"/>.
/// </summary>
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
/// <returns>The value for the attribute as a boolean.</returns>
public bool? GetBoolean(string attributeKey) => AttributeValueConverter.Convert<bool?>(GetValue(attributeKey));

/*==========================================================================================================================
| METHOD: GET INTEGER
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Gets an attribute value as an integer from the <see cref="AttributeDictionary"/> based on the <paramref name="
/// attributeKey"/>.
/// </summary>
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
/// <returns>The value for the attribute as an integer.</returns>
public int? GetInteger(string attributeKey) => AttributeValueConverter.Convert<int?>(GetValue(attributeKey));

/*==========================================================================================================================
| METHOD: GET DOUBLE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Gets an attribute value as a double from the <see cref="AttributeDictionary"/> based on the <paramref name="
/// attributeKey"/>.
/// </summary>
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
/// <returns>The value for the attribute as a double.</returns>
public double? GetDouble(string attributeKey) => AttributeValueConverter.Convert<double?>(GetValue(attributeKey));

/*==========================================================================================================================
| METHOD: GET DATETIME
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Gets an attribute value as a date/time from the <see cref="AttributeDictionary"/> based on the <paramref name="
/// attributeKey"/>.
/// </summary>
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
/// <returns>The value for the attribute as a DateTime object.</returns>
public DateTime? GetDateTime(string attributeKey) => AttributeValueConverter.Convert<DateTime?>(GetValue(attributeKey));

/*==========================================================================================================================
| METHOD: GET URI
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Gets an attribute value as a URI from the <see cref="AttributeDictionary"/> based on the <paramref name="attributeKey
/// "/>.
/// </summary>
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
/// <returns>The value for the attribute as a Uri object.</returns>
public Uri? GetUri(string attributeKey) => AttributeValueConverter.Convert<Uri?>(GetValue(attributeKey));

} //Class
} //Namespace

0 comments on commit 8e09fc5

Please sign in to comment.