Skip to content

Commit 74cb817

Browse files
committed
Add ItemConfiguration as property to ItemMetadata
The majority of the `ItemConfiguration` properties represent attributes (and their values) associated with individual parameters, properties, or methods, and whose values will not change at runtime. Given that, reidentifying these for every property incurs some overhead, and especially when we already have an `ItemMetadata` class for caching this information (via `TypeAccessor` and `TypeAccessorCache`). The one exception to this is the `attributePrefix` constructor argument, which conditionally updates the `AttributeKey` property. That is passed to calls to e.g. the `TopicMappingService` and `ReverseTopicMappingService`. In subsequent updates, that will be removed from the `ItemConfiguration`, and managed internally within those classes.
1 parent 65f6414 commit 74cb817

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

OnTopic/Internal/Reflection/ItemMetadata.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using System.Collections;
77
using System.Reflection;
88
using OnTopic.Attributes;
9+
using OnTopic.Mapping;
10+
using OnTopic.Mapping.Internal;
11+
using OnTopic.Mapping.Reverse;
912

1013
namespace OnTopic.Internal.Reflection {
1114

@@ -24,6 +27,7 @@ internal abstract class ItemMetadata {
2427
private readonly ICustomAttributeProvider _attributeProvider;
2528
private readonly Type _type = default!;
2629
private List<Attribute> _customAttributes = default!;
30+
private ItemConfiguration? _itemConfiguration;
2731

2832
/*==========================================================================================================================
2933
| CONSTRUCTOR
@@ -102,6 +106,26 @@ bool isList()
102106
}
103107
}
104108

109+
/*==========================================================================================================================
110+
| CONFIGURATION
111+
\-------------------------------------------------------------------------------------------------------------------------*/
112+
/// <summary>
113+
/// Gets a reference to the configuration settings for the current item, based on the annotations configured in the code.
114+
/// </summary>
115+
/// <remarks>
116+
/// The <see cref="ItemConfiguration"/> class identifies annotations used by the <see cref="TopicMappingService"/> and the
117+
/// <see cref="ReverseTopicMappingService"/>. While it can be called on any <see cref="Type"/>, it is only expected to
118+
/// offer a benefit for model classes intended for mapping.
119+
/// </remarks>
120+
internal ItemConfiguration Configuration {
121+
get {
122+
if (_itemConfiguration is null) {
123+
_itemConfiguration = new(this, Name, "");
124+
}
125+
return _itemConfiguration;
126+
}
127+
}
128+
105129
/*==========================================================================================================================
106130
| IS NULLABLE?
107131
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)