Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
Fix issue with objects inheriting from collections
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Mar 18, 2018
1 parent 9c48cf6 commit defd955
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T>") || targetClassSymbol.Kind == SymbolKind.ArrayType)
&& (HasInterface(sourceClassSymbol, "System.Collections.Generic.IEnumerable<T>") || 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(ITypeSymbol type)
}
}

private static bool IsSystemObject(ITypeSymbol current)
public static bool IsSystemObject(ITypeSymbol current)
{
return current.Name == "Object" && current.ContainingNamespace.Name =="System";
}
Expand Down

0 comments on commit defd955

Please sign in to comment.