Skip to content

Commit de92e13

Browse files
Fix generics and arrays
1 parent 68a546f commit de92e13

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

DeveloperCore.REPL/REPL.vb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Imports NuGet.Packaging.Core
1212
Imports NuGet.ProjectManagement
1313
Imports NuGet.Protocol.Core.Types
1414
Imports NuGet.Resolver
15-
'TODO: Multiple statements
15+
'TODO: Child variables only
16+
'TODO: Non method things
1617
Public Class REPL
1718
Private _imports As New List(Of ImportsStatementSyntax)
1819
Private _state As New Dictionary(Of String, Object)
@@ -85,7 +86,26 @@ Public Class REPL
8586

8687
Private Function GetTypeName(key As String) As String
8788
Dim obj As Object = _state(key)
88-
Return If(obj Is Nothing, "Object", obj.GetType.FullName)
89+
If obj Is Nothing Then
90+
Return "Object"
91+
Else
92+
Dim type As Type = obj.GetType
93+
Return GetTypeName(type)
94+
End If
95+
End Function
96+
97+
Public Function GetTypeName(type As Type) As String
98+
If type.IsGenericType Then
99+
Return SyntaxFactory.GenericName(GetGenericNameActual(type), SyntaxFactory.TypeArgumentList(New SeparatedSyntaxList(Of TypeSyntax)().AddRange(type.GenericTypeArguments.Select(Function(x) SyntaxFactory.ParseTypeName(GetTypeName(x)))))).NormalizeWhitespace.ToFullString
100+
ElseIf type.IsArray Then
101+
Return SyntaxFactory.ArrayType(SyntaxFactory.ParseTypeName(GetTypeName(type.GetElementType))).NormalizeWhitespace.ToFullString
102+
Else
103+
Return type.FullName
104+
End If
105+
End Function
106+
107+
Private Function GetGenericNameActual(type As Type) As String
108+
Return $"{type.Namespace}.{type.Name.Remove(type.Name.IndexOf("`"))}"
89109
End Function
90110

91111
Public Sub Reset()

0 commit comments

Comments
 (0)