Skip to content

Commit 63d32a2

Browse files
committed
Update ItemConfiguration to depend on new ItemMetadata
Previously, the `ItemConfiguration` accepted an `IEnumerable<Attribute>` (9705824), which is the common data used for `PropertyInfo`, `MethodInfo`, and `ParameterInfo`. Now, with the establishing of the `ItemMetadata` abstract class (bec7123), which is shared between `MemberAccessor` and the new `ParameterMetadata` (37eeb3c), we can instead accept an `ItemMetadata`. This gives us access to the `CustomAttributes`, just as before, but also provides access to additional metadata. This will allow better sharing (and caching) of state data in `TopicMappingService` by allowing properties to be assessed off of `ItemMetadata` instead of reevaluating reflection data for every call. That will come in subsequent commits.
1 parent 3659828 commit 63d32a2

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

OnTopic/Mapping/Internal/ItemConfiguration.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.ComponentModel;
88
using System.Reflection;
99
using OnTopic.Collections.Specialized;
10+
using OnTopic.Internal.Reflection;
1011
using OnTopic.Mapping.Annotations;
1112

1213
namespace OnTopic.Mapping.Internal {
@@ -44,18 +45,18 @@ internal class ItemConfiguration {
4445
/// Given an <see cref="IEnumerable{Attribute}"/> instance, exposes a set of properties associated with known
4546
/// <see cref="Attribute"/> instances.
4647
/// </summary>
47-
/// <param name="customAttributes">
48-
/// The <see cref="IEnumerable{Attribute}"/> instance to check for <see cref="Attribute"/> values.
48+
/// <param name="itemMetadata">
49+
/// The <see cref="ItemMetadata"/> instance associated with this <see cref="ItemConfiguration"/>.
4950
/// </param>
5051
/// <param name="name">The name of the <see cref="ParameterInfo"/> or <see cref="PropertyInfo"/>.</param>
5152
/// <param name="attributePrefix">The prefix to apply to the attributes.</param>
52-
internal ItemConfiguration(IEnumerable<Attribute> customAttributes, string name, string? attributePrefix = "") {
53+
internal ItemConfiguration(ItemMetadata itemMetadata, string name, string? attributePrefix = "") {
5354

5455
/*------------------------------------------------------------------------------------------------------------------------
55-
| Set backing property
56+
| Set backing properties
5657
\-----------------------------------------------------------------------------------------------------------------------*/
57-
CustomAttributes = customAttributes;
58-
var source = customAttributes;
58+
Metadata = itemMetadata;
59+
CustomAttributes = itemMetadata.CustomAttributes;
5960

6061
/*------------------------------------------------------------------------------------------------------------------------
6162
| Set default values
@@ -104,7 +105,7 @@ internal ItemConfiguration(IEnumerable<Attribute> customAttributes, string name,
104105
/*------------------------------------------------------------------------------------------------------------------------
105106
| Attributes: Set attribute filters
106107
\-----------------------------------------------------------------------------------------------------------------------*/
107-
var filterByAttributes = source.OfType<FilterByAttributeAttribute>();
108+
var filterByAttributes = CustomAttributes.OfType<FilterByAttributeAttribute>();
108109
if (filterByAttributes is not null && filterByAttributes.Any()) {
109110
foreach (var filter in filterByAttributes) {
110111
AttributeFilters.Add(filter.Key, filter.Value);
@@ -113,6 +114,14 @@ internal ItemConfiguration(IEnumerable<Attribute> customAttributes, string name,
113114

114115
}
115116

117+
/*==========================================================================================================================
118+
| PROPERTY: METADATA
119+
\-------------------------------------------------------------------------------------------------------------------------*/
120+
/// <summary>
121+
/// The <see cref="ItemMetadata"/> that the current <see cref="ItemConfiguration"/> is associated with.
122+
/// </summary>
123+
internal ItemMetadata Metadata { get; }
124+
116125
/*==========================================================================================================================
117126
| PROPERTY: CUSTOM ATTRIBUTES
118127
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic/Mapping/Internal/PropertyConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal class PropertyConfiguration: ItemConfiguration {
4444
/// </param>
4545
/// <param name="attributePrefix">The prefix to apply to the attributes.</param>
4646
internal PropertyConfiguration(MemberAccessor memberAccessor, string? attributePrefix = ""):
47-
base(memberAccessor.CustomAttributes, memberAccessor.Name, attributePrefix)
47+
base(memberAccessor, memberAccessor.Name, attributePrefix)
4848
{
4949
MemberAccessor = memberAccessor;
5050
}

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private async Task<object> MapAsync(
377377
/*------------------------------------------------------------------------------------------------------------------------
378378
| Establish per-property variables
379379
\-----------------------------------------------------------------------------------------------------------------------*/
380-
var configuration = new ItemConfiguration(parameter.CustomAttributes, parameter.Name, attributePrefix);
380+
var configuration = new ItemConfiguration(parameter, parameter.Name, attributePrefix);
381381

382382
/*------------------------------------------------------------------------------------------------------------------------
383383
| Bypass if mapping is disabled

0 commit comments

Comments
 (0)