Skip to content

Commit

Permalink
Use _mappings.UserMappings
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Nov 19, 2023
1 parent 25d2e30 commit d931e58
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Riok.Mapperly/Descriptors/DescriptorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Riok.Mapperly.Descriptors.ExternalMappings;
using Riok.Mapperly.Descriptors.MappingBodyBuilders;
using Riok.Mapperly.Descriptors.MappingBuilders;
using Riok.Mapperly.Descriptors.Mappings.UserMappings;
using Riok.Mapperly.Descriptors.ObjectFactories;
using Riok.Mapperly.Diagnostics;
using Riok.Mapperly.Helpers;
Expand Down Expand Up @@ -63,10 +62,10 @@ MapperConfiguration defaultMapperConfiguration
{
ConfigureMemberVisibility();
ReserveMethodNames();
var userMappings = ExtractUserMappings().ToList();
ExtractUserMappings();
// ExtractObjectFactories needs to be called after ExtractUserMappings due to configuring mapperDescriptor.Static
var objectFactories = ExtractObjectFactories();
EnqueueUserMappings(userMappings, objectFactories);
EnqueueUserMappings(objectFactories);
ExtractExternalMappings();
_mappingBodyBuilder.BuildMappingBodies(cancellationToken);
BuildMappingMethodNames();
Expand Down Expand Up @@ -108,7 +107,7 @@ private void ReserveMethodNames()
}
}

private IEnumerable<IUserMapping> ExtractUserMappings()
private void ExtractUserMappings()
{
_mapperDescriptor.Static = _mapperDescriptor.Symbol.IsStatic;
IMethodSymbol? firstNonStaticUserMapping = null;
Expand All @@ -128,8 +127,6 @@ private IEnumerable<IUserMapping> ExtractUserMappings()
}

_mappings.Add(userMapping);

yield return userMapping;
}

if (_mapperDescriptor.Static && firstNonStaticUserMapping is not null)
Expand All @@ -149,9 +146,9 @@ private ObjectFactoryCollection ExtractObjectFactories()
return ObjectFactoryBuilder.ExtractObjectFactories(_builderContext, _mapperDescriptor.Symbol);
}

private void EnqueueUserMappings(IReadOnlyCollection<IUserMapping> userMappings, ObjectFactoryCollection objectFactories)
private void EnqueueUserMappings(ObjectFactoryCollection objectFactories)
{
foreach (var userMapping in userMappings)
foreach (var userMapping in _mappings.UserMappings)
{
var ctx = new MappingBuilderContext(
_builderContext,
Expand Down

0 comments on commit d931e58

Please sign in to comment.