Types/OpenPackage.Part/Read.ps1

<#
.SYNOPSIS
    Reads Open Package Part
.DESCRIPTION
    Reads Open Package Parts, using the `.Reader` associated with this part.
#>

param(
    # An optional input object
    # If provided, content will be read from this object.
    # If not provided, content will be read from this part.
    [Alias('Input')]
    [PSObject]$InputObject = $null,
 
    # Any options used to read the data.
    [Alias('Options')]
    [Collections.IDictionary]$Option = [Ordered]@{}
)

# We want items returned from .Read to know their package and part
# so delcare a filter for that.
filter addPackageAndPart {
    $in = $_
    # Make sure we do not overwrite any information
    if ($in -and -not $in.package) {
        $in |
            Add-Member NoteProperty Package $this.Package -Force
    }    
    if ($in -and -not $in.partUri) {
        $in |
            Add-Member NoteProperty PartUri $this.Uri -Force
    }
    $_
}

$orderedMethods = @($this.Reader)

if (-not $orderedMethods) {
    Write-Warning "No reader found for $($this.Uri)"
    return
}
$method = $orderedMethods[0]
return $(
    $method.Invoke($InputObject, $Option) | addPackageAndPart
)