Strange behavior in PowerShell function returning DataSet/DataTable

前端 未结 3 809
轮回少年
轮回少年 2020-12-01 14:38

This is driving me crazy. I have a library I source from multiple scripts, which contains the following function:

function lib_open_dataset([string] $sql) {
         


        
3条回答
  •  一整个雨季
    2020-12-01 15:03

    PowerShell special-cases the DataTable internally. It does not implement any of the usual suspect interfaces like ICollection, IList or IEnumerable which normally trigger the unrolling. You can dig into this a bit with:

    PS> $dt = new-object data.datatable
    PS> $dt -is [collections.ienumerable]
    False
    

    Yet:

    PS> $e = [management.automation.languageprimitives]::GetEnumerator($dt)
    PS> $e.gettype()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    False    False    RBTreeEnumerator                         System.ValueType
    

    -Oisin

提交回复
热议问题