Skip to content

Commit fe39302

Browse files
committed
Relay ItemMetadata, attributePrefix instead of ItemConfiguration
With `ItemConfiguration` now a property on `ItemMetadata` (74cb817), it doesn't make sense to pass `ItemConfiguration` from method-to-method, but instead pass `ItemMetadata` (or `MemberAccessor` if specifically operating off of properties and methods). This effectively flips the order of dependencies, with `ItemConfiguration` being a property of `ItemMetadata` instead of `ItemMetadata` being a property of `Configuration`. In addition, I now pass the `attributePrefix` from method-to-method as well. This used to be part of the `ItemConfiguration`. Since it was the one (and only) runtime variable included in that, and since `ItemConfiguration` is now cached as part of the `TypeAccessorCache` hierarchy, the `attributePrefix` was removed from `ItemConfiguration`, thus breaking the `[MapToParent()]` functionality (84735fb). By passing it from method-to-method, we take the first step toward fixing this. As part of this, I also removed the `ItemMetadata` property from the `ItemConfiguration` class since it's no longer needed.
1 parent 84735fb commit fe39302

4 files changed

Lines changed: 150 additions & 114 deletions

File tree

OnTopic/Mapping/Internal/ItemConfiguration.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ internal ItemConfiguration(ItemMetadata itemMetadata) {
5353
/*------------------------------------------------------------------------------------------------------------------------
5454
| Set backing properties
5555
\-----------------------------------------------------------------------------------------------------------------------*/
56-
Metadata = itemMetadata;
5756
CustomAttributes = itemMetadata.CustomAttributes;
5857

5958
/*------------------------------------------------------------------------------------------------------------------------
@@ -112,14 +111,6 @@ internal ItemConfiguration(ItemMetadata itemMetadata) {
112111

113112
}
114113

115-
/*==========================================================================================================================
116-
| PROPERTY: METADATA
117-
\-------------------------------------------------------------------------------------------------------------------------*/
118-
/// <summary>
119-
/// The <see cref="ItemMetadata"/> that the current <see cref="ItemConfiguration"/> is associated with.
120-
/// </summary>
121-
internal ItemMetadata Metadata { get; }
122-
123114
/*==========================================================================================================================
124115
| PROPERTY: CUSTOM ATTRIBUTES
125116
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic/Mapping/Reverse/BindingModelValidator.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Reflection;
99
using OnTopic.Internal.Reflection;
1010
using OnTopic.Mapping.Annotations;
11-
using OnTopic.Mapping.Internal;
1211
using OnTopic.Metadata;
1312
using OnTopic.Models;
1413
using OnTopic.Repositories;
@@ -233,7 +232,7 @@ static internal void ValidateProperty(
233232
| Detect non-mapped relationships
234233
\-----------------------------------------------------------------------------------------------------------------------*/
235234
if (attributeDescriptor.ModelType is ModelType.Relationship) {
236-
ValidateRelationship(sourceType, configuration, attributeDescriptor, listType);
235+
ValidateRelationship(sourceType, propertyAccessor, attributeDescriptor, listType);
237236
}
238237

239238
/*------------------------------------------------------------------------------------------------------------------------
@@ -282,16 +281,16 @@ attributeDescriptor.ModelType is ModelType.Reference &&
282281
/// <param name="sourceType">
283282
/// The binding model <see cref="Type"/> to validate.
284283
/// </param>
285-
/// <param name="configuration">
286-
/// A <see cref="PropertyConfiguration"/> describing a specific property of the <paramref name="sourceType"/>.
284+
/// <param name="propertyAccessor">
285+
/// A <see cref="MemberAccessor"/> describing a specific property of the <paramref name="sourceType"/>.
287286
/// </param>
288287
/// <param name="attributeDescriptor">
289288
/// The <see cref="AttributeDescriptor"/> object against which to validate the model.
290289
/// </param>
291290
/// <param name="listType">The generic <see cref="Type"/> used for the corresponding <see cref="IList{T}"/>.</param>
292291
static internal void ValidateRelationship(
293292
[AllowNull]Type sourceType,
294-
[AllowNull]PropertyConfiguration configuration,
293+
[AllowNull]MemberAccessor propertyAccessor,
295294
[AllowNull]AttributeDescriptor attributeDescriptor,
296295
[DisallowNull]Type listType
297296
) {
@@ -300,20 +299,20 @@ [DisallowNull]Type listType
300299
| Validate parameters
301300
\-----------------------------------------------------------------------------------------------------------------------*/
302301
Contract.Requires(sourceType, nameof(sourceType));
303-
Contract.Requires(configuration, nameof(configuration));
302+
Contract.Requires(propertyAccessor, nameof(propertyAccessor));
304303
Contract.Requires(attributeDescriptor, nameof(attributeDescriptor));
305304

306305
/*------------------------------------------------------------------------------------------------------------------------
307306
| Define variables
308307
\-----------------------------------------------------------------------------------------------------------------------*/
309-
var property = configuration.MemberAccessor;
308+
var configuration = propertyAccessor.Configuration;
310309

311310
/*------------------------------------------------------------------------------------------------------------------------
312311
| Validate list
313312
\-----------------------------------------------------------------------------------------------------------------------*/
314-
if (!typeof(IList).IsAssignableFrom(property.Type)) {
313+
if (!typeof(IList).IsAssignableFrom(propertyAccessor.Type)) {
315314
throw new MappingModelValidationException(
316-
$"The '{property.Name}' property on the '{sourceType.Name}' class maps to a relationship attribute " +
315+
$"The '{propertyAccessor.Name}' property on the '{sourceType.Name}' class maps to a relationship attribute " +
317316
$"'{attributeDescriptor.Key}', but does not implement {nameof(IList)}. Relationships must implement " +
318317
$"{nameof(IList)} or derive from a collection that does."
319318
);
@@ -324,7 +323,7 @@ [DisallowNull]Type listType
324323
\-----------------------------------------------------------------------------------------------------------------------*/
325324
if (!new[] { CollectionType.Any, CollectionType.Relationship }.Contains(configuration.CollectionType)) {
326325
throw new MappingModelValidationException(
327-
$"The '{property.Name}' property on the '{sourceType.Name}' class maps to a relationship attribute " +
326+
$"The '{propertyAccessor.Name}' property on the '{sourceType.Name}' class maps to a relationship attribute " +
328327
$"'{attributeDescriptor.Key}', but is configured as a {configuration.CollectionType}. The property should be " +
329328
$"flagged as either {nameof(CollectionType.Any)} or {nameof(CollectionType.Relationship)}."
330329
);
@@ -335,7 +334,7 @@ [DisallowNull]Type listType
335334
\-----------------------------------------------------------------------------------------------------------------------*/
336335
if (!typeof(IAssociatedTopicBindingModel).IsAssignableFrom(listType)) {
337336
throw new MappingModelValidationException(
338-
$"The '{property.Name}' property on the '{sourceType.Name}' class has been determined to be a " +
337+
$"The '{propertyAccessor.Name}' property on the '{sourceType.Name}' class has been determined to be a " +
339338
$"{configuration.CollectionType}, but the generic type '{listType.Name}' does not implement the " +
340339
$"{nameof(IAssociatedTopicBindingModel)} interface. This is required for binding models. If this collection is not " +
341340
$"intended to be mapped as a {configuration.CollectionType} then update the definition in the associated " +

0 commit comments

Comments
 (0)