Skip to content

Commit 2bf635e

Browse files
committed
Reintroduced attributePrefix to BindingModelValidator
In #751c259b, we removed the `attributePrefix` parameter because it was now being handled as part of the `PropertyConfiguration` object, which represented a much more elegant approach to relaying that context for `[MapToParent]`. The only problem? We weren't passing a `PropertyConfiguration` object to to `ValidateModel`; instead, it was creating its own. And when it did? It wasn't actually passing the contextual `attributePrefix` to it. As such, when it recursed down to child properties, it was losing the context. This bug was overlooked by the `Map_ComplexObject_ReturnsFlattenedTopic` unit test since the `Contact` content type had an `Email` attribute. As such, when the validator was supposed to be validating e.g. `AlternateEmail`, it was _actually_ validating `Email`, and passing. In a real-world scenario, however, this won't usually be the case, and defeats the benefit of validating the model against the content type. This fix effectively undoes #751c259b, and restores the `BindingModelValidator` to its prior state.
1 parent de79c61 commit 2bf635e

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

OnTopic/Mapping/BindingModelValidator.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ static internal class BindingModelValidator {
8787
/// <param name="contentTypeDescriptor">
8888
/// The <see cref="ContentTypeDescriptor"/> object against which to validate the model.
8989
/// </param>
90+
/// <param name="attributePrefix">The prefix to apply to the attributes.</param>
9091
static internal void ValidateModel(
9192
[AllowNull]Type sourceType,
9293
[AllowNull]MemberInfoCollection<PropertyInfo> properties,
93-
[AllowNull]ContentTypeDescriptor contentTypeDescriptor
94+
[AllowNull]ContentTypeDescriptor contentTypeDescriptor,
95+
[AllowNull]String attributePrefix = ""
9496
) {
9597

9698
/*------------------------------------------------------------------------------------------------------------------------
@@ -111,7 +113,7 @@ [AllowNull]ContentTypeDescriptor contentTypeDescriptor
111113
| Validate
112114
\-----------------------------------------------------------------------------------------------------------------------*/
113115
foreach (var property in properties) {
114-
ValidateProperty(sourceType, property, contentTypeDescriptor);
116+
ValidateProperty(sourceType, property, contentTypeDescriptor, attributePrefix);
115117
}
116118

117119
/*------------------------------------------------------------------------------------------------------------------------
@@ -139,10 +141,12 @@ [AllowNull]ContentTypeDescriptor contentTypeDescriptor
139141
/// <param name="contentTypeDescriptor">
140142
/// The <see cref="ContentTypeDescriptor"/> object against which to validate the model.
141143
/// </param>
144+
/// <param name="attributePrefix">The prefix to apply to the attributes.</param>
142145
static internal void ValidateProperty(
143146
[AllowNull]Type sourceType,
144147
[AllowNull]PropertyInfo property,
145-
[AllowNull]ContentTypeDescriptor contentTypeDescriptor
148+
[AllowNull]ContentTypeDescriptor contentTypeDescriptor,
149+
[AllowNull]String attributePrefix = ""
146150
) {
147151

148152
/*------------------------------------------------------------------------------------------------------------------------
@@ -156,7 +160,7 @@ [AllowNull]ContentTypeDescriptor contentTypeDescriptor
156160
| Define variables
157161
\-----------------------------------------------------------------------------------------------------------------------*/
158162
var propertyType = property.PropertyType;
159-
var configuration = new PropertyConfiguration(property);
163+
var configuration = new PropertyConfiguration(property, attributePrefix);
160164
var compositeAttributeKey = configuration.AttributeKey;
161165
var attributeDescriptor = contentTypeDescriptor.AttributeDescriptors.GetTopic(compositeAttributeKey);
162166
var childRelationships = new[] { RelationshipType.Children, RelationshipType.NestedTopics };
@@ -178,7 +182,8 @@ [AllowNull]ContentTypeDescriptor contentTypeDescriptor
178182
ValidateModel(
179183
propertyType,
180184
childProperties,
181-
contentTypeDescriptor
185+
contentTypeDescriptor,
186+
configuration.AttributePrefix
182187
);
183188
return;
184189
}

0 commit comments

Comments
 (0)