@@ -30,19 +30,6 @@ public class TopicMappingService : ITopicMappingService {
3030 \-------------------------------------------------------------------------------------------------------------------------*/
3131 readonly ITopicRepository _topicRepository ;
3232 readonly ITypeLookupService _typeLookupService ;
33- static readonly List < Type > _listTypes = new ( ) ;
34-
35- /*==========================================================================================================================
36- | CONSTRUCTOR
37- \-------------------------------------------------------------------------------------------------------------------------*/
38- /// <summary>
39- /// Establishes a new instance of a <see cref="TopicMappingService"/> with required dependencies.
40- /// </summary>
41- static TopicMappingService ( ) {
42- _listTypes . Add ( typeof ( IEnumerable < > ) ) ;
43- _listTypes . Add ( typeof ( ICollection < > ) ) ;
44- _listTypes . Add ( typeof ( IList < > ) ) ;
45- }
4633
4734 /*==========================================================================================================================
4835 | CONSTRUCTOR
@@ -404,7 +391,7 @@ private async Task<object> MapAsync(
404391 \-----------------------------------------------------------------------------------------------------------------------*/
405392 var value = await GetValue ( source , parameter . Type , associations , configuration , cache , false ) . ConfigureAwait ( false ) ;
406393
407- if ( value is null && IsList ( parameter . Type ) ) {
394+ if ( value is null && parameter . IsList ) {
408395 return await getList ( parameter . Type , configuration ) . ConfigureAwait ( false ) ;
409396 }
410397
@@ -487,7 +474,7 @@ await MapAsync(
487474 \-----------------------------------------------------------------------------------------------------------------------*/
488475 else {
489476 var value = await GetValue ( source , propertyAccessor . Type , associations , configuration , cache , mapAssociationsOnly ) . ConfigureAwait ( false ) ;
490- if ( value is null && IsList ( propertyAccessor . Type ) ) {
477+ if ( value is null && propertyAccessor . IsList ) {
491478 await SetCollectionValueAsync ( source , target , associations , configuration , cache ) . ConfigureAwait ( false ) ;
492479 }
493480 else if ( value != null && propertyAccessor . CanWrite ) {
@@ -545,12 +532,12 @@ await MapAsync(
545532 value = await GetTopicReferenceAsync ( source . Parent , targetType , configuration , cache ) . ConfigureAwait ( false ) ;
546533 }
547534 }
548- else if ( AttributeValueConverter . IsConvertible ( targetType ) ) {
535+ else if ( configuration . Metadata . IsConvertible ) {
549536 if ( ! mapAssociationsOnly ) {
550537 value = GetScalarValue ( source , configuration ) ;
551538 }
552539 }
553- else if ( IsList ( targetType ) ) {
540+ else if ( configuration . Metadata . IsList ) {
554541 return null ;
555542 }
556543 else if ( associations . HasFlag ( AssociationTypes . References ) ) {
@@ -641,33 +628,6 @@ await MapAsync(
641628
642629 }
643630
644- /*==========================================================================================================================
645- | PRIVATE: IS LIST?
646- \-------------------------------------------------------------------------------------------------------------------------*/
647- /// <summary>
648- /// Given a type, determines whether it's a list that is recognized by the <see cref="TopicMappingService"/>.
649- /// </summary>
650- /// <remarks>
651- /// <para>
652- /// To qualify, the <paramref name="targetType"/> must either implement <see cref="IList"/>, or it must be of type <see
653- /// cref="IEnumerable{T}"/>, <see cref="ICollection{T}"/>, or <see cref="IList{T}"/>—any of which, if null, will be
654- /// instantiated as a new <see cref="List{T}"/>.
655- /// </para>
656- /// <para>
657- /// It is technically possible for the <paramref name="targetType"/> to implement one of the interfaces, such as <see
658- /// cref="IList{T}"/>, while the assigned reference type is not compatible with the <see cref="IList"/> interface
659- /// required by e.g. <see cref="PopulateTargetCollectionAsync(IList{Topic}, IList, ItemConfiguration, MappedTopicCache)"
660- /// />. Detecting this requires looping through the interface implementations which is comparatively more costly given
661- /// the number of times <see cref="IsList(Type)"/> gets called. In practice, collections that implement e.g. <see cref="
662- /// IList{T}"/> are expected to also support <see cref="IList"/>. If they don't, however, the mapping will throw an
663- /// exception since the assigned value will not be castable to an <see cref="IList"/>.
664- /// </para>
665- /// </remarks>
666- /// <param name="targetType">The <see cref="Type"/> of collection to initialize.</param>
667- private static bool IsList ( Type targetType ) =>
668- typeof ( IList ) . IsAssignableFrom ( targetType ) ||
669- targetType . IsGenericType && _listTypes . Contains ( targetType . GetGenericTypeDefinition ( ) ) ;
670-
671631 /*==========================================================================================================================
672632 | PRIVATE: INITIALIZE COLLECTION
673633 \-------------------------------------------------------------------------------------------------------------------------*/
0 commit comments