Where does PowerShell retrieve Intellisense/AutoComplete information from (specifically for .NET class methods)?

118 views Asked by At

In the console, if I type [string]::Concat( and press CTRL + SPACE I can see every method overload. Where exactly does PowerShell retrieve this kind of overload definition/syntax information from?

PS C:\> [string]::Concat(
Empty               CompareOrdinal      Copy                Format              IsInterned          IsNullOrWhiteSpace  new
Compare             Concat              Equals              Intern              IsNullOrEmpty       Join                ReferenceEquals

static string Concat(System.Object arg0)
static string Concat(System.Object arg0, System.Object arg1)
static string Concat(System.Object arg0, System.Object arg1, System.Object arg2)
static string Concat(System.Object arg0, System.Object arg1, System.Object arg2, System.Object arg3)
static string Concat(Params System.Object[] args)
static string Concat(System.Collections.Generic.IEnumerable[string] values)
static string Concat(string str0, string str1)
static string Concat(string str0, string str1, string str2)
static string Concat(string str0, string str1, string str2, string str3)
static string Concat(Params string[] values)
static string Concat[T](System.Collections.Generic.IEnumerable[T] values)



I can hack together an object that outputs similar information, but it's not quite the same.

$Obj = foreach ($method in [System.String].GetMethods())
{
    $params = @($method.GetParameters() | Select-Object @{n='Overloads';e={ ([string]$_.ParameterType.FullName) + ' ' + ([string]$_.Name)}})
    if ($null -ne $params.Overloads)
    {
        $parameterDescription = [string]::Join(', ', ($params.Overloads))
        [pscustomobject][ordered] @{
            'MethodName' = $Method.Name
            'MethodType' = $(if ($method.IsStatic) {'static'} else {'instance'})
            'ReturnType' = $method.ReturnType.Name
            'Overloads' = $Method.Name + '(' + $parameterDescription + ')'
        }
    }
}
$Obj | Where-Object {$_.MethodName -eq 'Concat'}

MethodName MethodType ReturnType Overloads                                                                                                                                            
---------- ---------- ---------- ---------                                                                                                                                            
Concat     static     String     Concat(System.Object arg0)                                                                                                                           
Concat     static     String     Concat(System.Object arg0, System.Object arg1)                                                                                                       
Concat     static     String     Concat(System.Object arg0, System.Object arg1, System.Object arg2)                                                                                   
Concat     static     String     Concat(System.Object arg0, System.Object arg1, System.Object arg2, System.Object arg3)                                                               
Concat     static     String     Concat(System.Object[] args)                                                                                                                         
Concat     static     String     Concat(System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] values)
Concat     static     String     Concat(System.String str0, System.String str1)                                                                                                       
Concat     static     String     Concat(System.String str0, System.String str1, System.String str2)                                                                                   
Concat     static     String     Concat(System.String str0, System.String str1, System.String str2, System.String str3)                                                               
Concat     static     String     Concat(System.String[] values)                                                                                                                       
Concat     static     String     Concat( values)  

In the code I've haphazardly thrown together, I can get 2x different versions of the overload definition/syntax (depending on if $params uses ParameterType.FullName vs ParameterType.Name) -- but neither reflect (no pun intended) the exact intellisense/autocomplete text (e.g. the 5th, 6th and 11th overloads especially), hence my question:

Where exactly does PowerShell retrieve the intellisense/autocomplete information from in the case of .NET class methods?

Update

I found that using $_.ParameterType rather than $_.ParameterType.Name or $_.ParameterType.FullName (in $params) gets a little bit closer to the OverloadDefinition text, but not 100%:

$Obj = foreach ($method in [System.String].GetMethods())
{
    $params = @($method.GetParameters() | Select-Object @{n='Overloads';e={ ([string]$_.ParameterType) + ' ' + ([string]$_.Name)}})
    if ($null -ne $params.Overloads)
    {
        $parameterDescription = [string]::Join(', ', ($params.Overloads))
        [pscustomobject][ordered] @{
            'MethodName' = $Method.Name
            'MethodType' = $(if ($method.IsStatic) {'static'} else {'instance'})
            'ReturnType' = $method.ReturnType.Name
            'Overloads' = $Method.Name + '(' + $parameterDescription + ')'
        }
    }
}
$Obj | Where-Object {$_.MethodName -eq 'Concat'}

MethodName MethodType ReturnType Overloads                                                                             
---------- ---------- ---------- ---------                                                                             
Concat     static     String     Concat(System.Object arg0)                                                            
Concat     static     String     Concat(System.Object arg0, System.Object arg1)                                        
Concat     static     String     Concat(System.Object arg0, System.Object arg1, System.Object arg2)                    
Concat     static     String     Concat(System.Object arg0, System.Object arg1, System.Object arg2, System.Object arg3)
Concat     static     String     Concat(System.Object[] args)                                                          
Concat     static     String     Concat(System.Collections.Generic.IEnumerable[string] values)                         
Concat     static     String     Concat(string str0, string str1)                                                      
Concat     static     String     Concat(string str0, string str1, string str2)                                         
Concat     static     String     Concat(string str0, string str1, string str2, string str3)                            
Concat     static     String     Concat(string[] values)                                                               
Concat     static     String     Concat(System.Collections.Generic.IEnumerable[T] values)
0

There are 0 answers