Skip to content

Commit 8e09fc5

Browse files
committed
Added strongly types conveniences methods to AttributeDictionary
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.
1 parent 30bd3e5 commit 8e09fc5

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

OnTopic/Attributes/AttributeDictionary.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,60 @@ public AttributeDictionary(): base(StringComparer.OrdinalIgnoreCase) { }
4343
return String.IsNullOrWhiteSpace(value)? null : value;
4444
}
4545

46+
/*==========================================================================================================================
47+
| METHOD: GET BOOLEAN VALUE
48+
\-------------------------------------------------------------------------------------------------------------------------*/
49+
/// <summary>
50+
/// Gets an attribute value as a Boolean from the <see cref="AttributeDictionary"/> based on the <paramref name="
51+
/// attributeKey"/>.
52+
/// </summary>
53+
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
54+
/// <returns>The value for the attribute as a boolean.</returns>
55+
public bool? GetBoolean(string attributeKey) => AttributeValueConverter.Convert<bool?>(GetValue(attributeKey));
56+
57+
/*==========================================================================================================================
58+
| METHOD: GET INTEGER
59+
\-------------------------------------------------------------------------------------------------------------------------*/
60+
/// <summary>
61+
/// Gets an attribute value as an integer from the <see cref="AttributeDictionary"/> based on the <paramref name="
62+
/// attributeKey"/>.
63+
/// </summary>
64+
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
65+
/// <returns>The value for the attribute as an integer.</returns>
66+
public int? GetInteger(string attributeKey) => AttributeValueConverter.Convert<int?>(GetValue(attributeKey));
67+
68+
/*==========================================================================================================================
69+
| METHOD: GET DOUBLE
70+
\-------------------------------------------------------------------------------------------------------------------------*/
71+
/// <summary>
72+
/// Gets an attribute value as a double from the <see cref="AttributeDictionary"/> based on the <paramref name="
73+
/// attributeKey"/>.
74+
/// </summary>
75+
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
76+
/// <returns>The value for the attribute as a double.</returns>
77+
public double? GetDouble(string attributeKey) => AttributeValueConverter.Convert<double?>(GetValue(attributeKey));
78+
79+
/*==========================================================================================================================
80+
| METHOD: GET DATETIME
81+
\-------------------------------------------------------------------------------------------------------------------------*/
82+
/// <summary>
83+
/// Gets an attribute value as a date/time from the <see cref="AttributeDictionary"/> based on the <paramref name="
84+
/// attributeKey"/>.
85+
/// </summary>
86+
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
87+
/// <returns>The value for the attribute as a DateTime object.</returns>
88+
public DateTime? GetDateTime(string attributeKey) => AttributeValueConverter.Convert<DateTime?>(GetValue(attributeKey));
89+
90+
/*==========================================================================================================================
91+
| METHOD: GET URI
92+
\-------------------------------------------------------------------------------------------------------------------------*/
93+
/// <summary>
94+
/// Gets an attribute value as a URI from the <see cref="AttributeDictionary"/> based on the <paramref name="attributeKey
95+
/// "/>.
96+
/// </summary>
97+
/// <param name="attributeKey">The string identifier for the <see cref="AttributeRecord"/>.</param>
98+
/// <returns>The value for the attribute as a Uri object.</returns>
99+
public Uri? GetUri(string attributeKey) => AttributeValueConverter.Convert<Uri?>(GetValue(attributeKey));
46100

47101
} //Class
48102
} //Namespace

0 commit comments

Comments
 (0)