Commits

Oisin Grehan committed ee4e534

compatibility fixes for v3 beta

  • Participants
  • Parent commits 6dfa4a8

Comments (0)

Files changed (3)

     
     # cache some often used members for performance reasons
     $SCRIPT:miType = [psobject].assembly.gettype("System.Management.Automation.MethodInformation")
-    $SCRIPT:miCtor = $mitype.GetConstructor("nonpublic,instance", $null, [type[]]@([reflection.methodinfo], [int]), $null)
+    
+    $SCRIPT:miCtor = $mitype.GetConstructor("nonpublic,instance", $null, [type[]]@([reflection.methodinfo], [int]), $null)    
     $SCRIPT:miDefinition = $mitype.GetProperty("methodDefinition", [reflection.bindingflags]"instance,nonpublic")
 
+    $SCRIPT:fieldCall = $false
+
+    # workaround
+    if (-not $miDefinition) {
+        $SCRIPT:miCtor = $mitype.GetConstructor("nonpublic,instance", $null, [type[]]@([string],[reflection.methodinfo], [int]), $null)
+        $SCRIPT:miDefinition = $mitype.GetField("methodDefinition", [reflection.bindingflags]"instance,nonpublic")    
+        $SCRIPT:fieldCall = $true
+    }
+
     # used in dynamic modules (proxies) for method filter
     filter Limit-SpecialMember {
         if (-not ($_.isspecialname -or $_.GetCustomAttributes([System.Runtime.CompilerServices.CompilerGeneratedAttribute], $false).count)) {
             [reflection.methodinfo]$MethodInfo
         )
         # let powershell do the work
-        $mi = $miCtor.Invoke(@($MethodInfo, 0))
-        $miDefinition.getvalue($mi, @()) # 4.0 compat
+        if ($SCRIPT:fieldCall) {
+            $mi = $miCtor.Invoke(@($methodinfo.name, $MethodInfo, 0))
+            $miDefinition.getvalue($mi) # field call
+        } else {
+            $mi = $miCtor.Invoke(@($MethodInfo, 0))
+            $miDefinition.getvalue($mi, @()) # prop call
+        }
     }
 
     function Get-MemberDefinition {
         $done.invoke($serializer, @())
         $sw.ToString()
     }
-}
+}
+
+<#
+# ipmo poke
+function ConvertTo-CliXml {
+    param(
+        [parameter(position=0,mandatory=$true,valuefrompipeline=$true)]
+        [validatenotnull()]
+        [psobject]$object
+    )
+    begin {
+        $type = peek -name System.Management.Automation.Serializer
+        $sw = new-object io.stringwriter
+        $xw = new-object xml.xmltextwriter $sw
+
+        # need to cast due to powershell not unwrapping array elements
+        # from their psobject covers
+        $serializer = $type.__createinstance([xml.xmltextwriter]$xw)
+    }
+
+    process {
+        try {
+            $serializer.Serialize($_)
+        } catch {
+            write-warning "Could not serialize $($object.gettype()): $_"
+        }
+    }
+
+    end {
+        $serializer.Done()
+        $sw.tostring()
+    }
+}
+#>

File test-poke.ps1

-cd $psscriptroot
+cls
+
+cd $psscriptroot
 ipmo .\poke.psd1 -force
 
 #$VerbosePreference = "Continue"