Powershell CmdLet and Disposable Fields / CA1001

What is an acceptable template for CmdLets and disposable fields?

FxCop rule: types that have disposable fields must be disposable

But if PowerShell doesn't call the dispose method ... it really won't help implement the template.

so far, I am using Begin / EndProcessing methods to configure and clear fields.

Unfortunately, I could not find the documentation on whether PowerShell is calling the Dispose method correctly.

+4
source share
1 answer

When you implement the Cmdlet (or PSCmdlet) command that implements IDisposable, PowerShell will use your command for you when the pipeline completes. It is so simple. Do you see behavior that contradicts this?

Update, a la LetMeGoogleThatForYou:

"... For this reason, the cmdlet that requires cleaning the object must implement the full IDisposable template, including the finalizer, so that the runtime can call both System.Management.Automation.Cmdlet.EndProcessing and Dispose Methods at the end of processing."

From: http://msdn.microsoft.com/en-us/library/windows/desktop/ms714463(v=vs.85).aspx

+5
source

All Articles