A: No. However, the PowerShell team very kindly came up with a simple implementation, detailed here:
It looks like this:
function using
{
param($obj, [scriptblock]$sb)
try {
& $sb
} finally {
if ($obj -is [IDisposable]) {
$obj.Dispose()
}
}
}
Here's the example:
using ($stream = new-object System.IO.StreamReader $PSHOME\types.ps1xml) {
foreach ($_ in 1..5) { $stream.ReadLine() }
}
0 comments:
Post a Comment