diff --git a/MappingGenerator/MappingGenerator/MappingGenerator/MappingGenerator.cs b/MappingGenerator/MappingGenerator/MappingGenerator/MappingGenerator.cs index a0cd78b..6669f35 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator/MappingGenerator.cs +++ b/MappingGenerator/MappingGenerator/MappingGenerator/MappingGenerator.cs @@ -160,11 +160,19 @@ private SyntaxNode MapCollections(SyntaxNode sourceAccess, ITypeSymbol sourceLis return WrapInReadonlyCollectionIfNecessary(isReadolyCollection, toList, generator); } - private static ITypeSymbol GetElementType(ITypeSymbol collectionType) + private ITypeSymbol GetElementType(ITypeSymbol collectionType) { switch (collectionType) { case INamedTypeSymbol namedType: + if (namedType.IsGenericType == false) + { + if (ObjectHelper.IsSystemObject(namedType.BaseType)) + { + return namedType.BaseType; + } + return GetElementType(namedType.BaseType); + } return namedType.TypeArguments[0]; case IArrayTypeSymbol arrayType: return arrayType.ElementType; @@ -193,8 +201,8 @@ private static SyntaxNode WrapInReadonlyCollectionIfNecessary(bool isReadonly, S private static bool IsMappingBetweenCollections(ITypeSymbol targetClassSymbol, ITypeSymbol sourceClassSymbol) { - return (HasInterface(targetClassSymbol, "System.Collections.Generic.ICollection") || targetClassSymbol.Kind == SymbolKind.ArrayType) - && (HasInterface(sourceClassSymbol, "System.Collections.Generic.IEnumerable") || sourceClassSymbol.Kind == SymbolKind.ArrayType); + return (HasInterface(targetClassSymbol, "System.Collections.ICollection") || targetClassSymbol.Kind == SymbolKind.ArrayType) + && (HasInterface(sourceClassSymbol, "System.Collections.IEnumerable") || sourceClassSymbol.Kind == SymbolKind.ArrayType); } private ArgumentListSyntax FindMappingConstructorParameters(ITypeSymbol targetType, ITypeSymbol sourceType, ObjectMembersMappingSourceFinder mappingSourceFinder, ExpressionSyntax globalSourceAccessor) diff --git a/MappingGenerator/MappingGenerator/MappingGenerator/ObjectHelper.cs b/MappingGenerator/MappingGenerator/MappingGenerator/ObjectHelper.cs index 26d7ede..94255bb 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator/ObjectHelper.cs +++ b/MappingGenerator/MappingGenerator/MappingGenerator/ObjectHelper.cs @@ -70,7 +70,7 @@ private static IEnumerable GetBaseTypesAndThis(ITypeSymbol type) } } - private static bool IsSystemObject(ITypeSymbol current) + public static bool IsSystemObject(ITypeSymbol current) { return current.Name == "Object" && current.ContainingNamespace.Name =="System"; }