Skip to content

Commit

Permalink
Fix generics and arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCoderSuper committed Oct 27, 2023
1 parent 68a546f commit de92e13
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions DeveloperCore.REPL/REPL.vb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Imports NuGet.Packaging.Core
Imports NuGet.ProjectManagement
Imports NuGet.Protocol.Core.Types
Imports NuGet.Resolver
'TODO: Multiple statements
'TODO: Child variables only
'TODO: Non method things
Public Class REPL
Private _imports As New List(Of ImportsStatementSyntax)
Private _state As New Dictionary(Of String, Object)
Expand Down Expand Up @@ -85,7 +86,26 @@ Public Class REPL

Private Function GetTypeName(key As String) As String
Dim obj As Object = _state(key)
Return If(obj Is Nothing, "Object", obj.GetType.FullName)
If obj Is Nothing Then
Return "Object"
Else
Dim type As Type = obj.GetType
Return GetTypeName(type)
End If
End Function

Public Function GetTypeName(type As Type) As String
If type.IsGenericType Then
Return SyntaxFactory.GenericName(GetGenericNameActual(type), SyntaxFactory.TypeArgumentList(New SeparatedSyntaxList(Of TypeSyntax)().AddRange(type.GenericTypeArguments.Select(Function(x) SyntaxFactory.ParseTypeName(GetTypeName(x)))))).NormalizeWhitespace.ToFullString
ElseIf type.IsArray Then
Return SyntaxFactory.ArrayType(SyntaxFactory.ParseTypeName(GetTypeName(type.GetElementType))).NormalizeWhitespace.ToFullString
Else
Return type.FullName
End If
End Function

Private Function GetGenericNameActual(type As Type) As String
Return $"{type.Namespace}.{type.Name.Remove(type.Name.IndexOf("`"))}"
End Function

Public Sub Reset()
Expand Down

0 comments on commit de92e13

Please sign in to comment.