Skip to content

Commit 3659828

Browse files
committed
Updated TopicMappingService to use new ParameterMetadata
In `TopicMappingService`, when evaluating parameters, we now pull a list of `ParameterMetadata` from the `TypeAccessor`, instead of calling `GetPrimaryConstructor()` for each instance. This should provide a slight improvement to performance. Outside of that, this doesn't buy us too much yet—though it will be get us more functionality in a bit, once we incorporate it into `ItemConfiguration` as well. That'll come in a subsequent commit. As part of this, this required updating the parameters and member calls to work off of `ParameterMetadata` instead of `ParameterInfo`.
1 parent 863b618 commit 3659828

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ public TopicMappingService(ITopicRepository topicRepository, ITypeLookupService
182182
| Identify parameters
183183
\-----------------------------------------------------------------------------------------------------------------------*/
184184
var typeAccessor = TypeAccessorCache.GetTypeAccessor(type);
185-
var constructorInfo = typeAccessor.GetPrimaryConstructor();
186-
var parameters = constructorInfo?.GetParameters()?? Array.Empty<ParameterInfo>();
187-
var arguments = new object?[parameters.Length];
185+
var parameters = typeAccessor.ConstructorParameters;
186+
var arguments = new object?[parameters.Count];
188187
var attributeArguments = (IDictionary<string, string?>)new Dictionary<string, string?>();
189188

190189
/*------------------------------------------------------------------------------------------------------------------------
@@ -202,15 +201,15 @@ public TopicMappingService(ITopicRepository topicRepository, ITypeLookupService
202201
\-----------------------------------------------------------------------------------------------------------------------*/
203202
var parameterQueue = new Dictionary<int, Task<object?>>();
204203

205-
if (parameters.Length == 1 && parameters[0].ParameterType == typeof(AttributeDictionary)) {
204+
if (parameters.Count is 1 && parameters[0].Type == typeof(AttributeDictionary)) {
206205
var attributes = topic.Attributes.AsAttributeDictionary(true);
207206
arguments[0] = attributes;
208207
attributeArguments = attributes;
209208
}
210209
else {
211210

212211
foreach (var parameter in parameters) {
213-
parameterQueue.Add(parameter.Position, GetParameterAsync(topic, associations, parameter, cache, attributePrefix));
212+
parameterQueue.Add(parameter.ParameterInfo.Position, GetParameterAsync(topic, associations, parameter, cache, attributePrefix));
214213
}
215214

216215
await Task.WhenAll(parameterQueue.Values).ConfigureAwait(false);
@@ -370,22 +369,21 @@ private async Task<object> MapAsync(
370369
private async Task<object?> GetParameterAsync(
371370
Topic source,
372371
AssociationTypes associations,
373-
ParameterInfo parameter,
372+
ParameterMetadata parameter,
374373
MappedTopicCache cache,
375374
string? attributePrefix = null
376375
) {
377376

378377
/*------------------------------------------------------------------------------------------------------------------------
379378
| Establish per-property variables
380379
\-----------------------------------------------------------------------------------------------------------------------*/
381-
var attributes = parameter.GetCustomAttributes(true).OfType<Attribute>();
382-
var configuration = new ItemConfiguration(attributes, parameter.Name, attributePrefix);
380+
var configuration = new ItemConfiguration(parameter.CustomAttributes, parameter.Name, attributePrefix);
383381

384382
/*------------------------------------------------------------------------------------------------------------------------
385383
| Bypass if mapping is disabled
386384
\-----------------------------------------------------------------------------------------------------------------------*/
387385
if (configuration.DisableMapping) {
388-
return parameter.DefaultValue;
386+
return parameter.ParameterInfo.DefaultValue;
389387
}
390388

391389
/*------------------------------------------------------------------------------------------------------------------------
@@ -394,7 +392,7 @@ private async Task<object> MapAsync(
394392
if (configuration.MapToParent) {
395393
return await MapAsync(
396394
source,
397-
parameter.ParameterType,
395+
parameter.Type,
398396
associations,
399397
cache,
400398
configuration.AttributePrefix
@@ -404,10 +402,10 @@ private async Task<object> MapAsync(
404402
/*------------------------------------------------------------------------------------------------------------------------
405403
| Determine value
406404
\-----------------------------------------------------------------------------------------------------------------------*/
407-
var value = await GetValue(source, parameter.ParameterType, associations, configuration, cache, false).ConfigureAwait(false);
405+
var value = await GetValue(source, parameter.Type, associations, configuration, cache, false).ConfigureAwait(false);
408406

409-
if (value is null && IsList(parameter.ParameterType)) {
410-
return await getList(parameter.ParameterType, configuration).ConfigureAwait(false);
407+
if (value is null && IsList(parameter.Type)) {
408+
return await getList(parameter.Type, configuration).ConfigureAwait(false);
411409
}
412410

413411
return value;

0 commit comments

Comments
 (0)