Bemeneti feldolgozási módszerek felülbírálása
Ezek a példák bemutatják, hogyan írhatja felül a parancsmagok bemeneti feldolgozási módszereit. Ezek a metódusok a következő műveletek végrehajtásához használhatók:
A System.Management.Automation.Cmdlet.BeginProcessing metódussal olyan egyszeres indítási műveleteket hajthat végre, amelyek érvényesek a parancsmag által feldolgozott összes objektumra. A Windows PowerShell futtatás csak egyszer hívja meg ezt a metódust.
A System.Management.Automation.Cmdlet.ProcessRecord metódus a parancsmagnak átadott objektumok feldolgozására használatos. A Windows PowerShell a parancsmagnak átadott minden egyes objektumhoz ezt a metódust hívja meg.
A System.Management.Automation.Cmdlet.EndProcessing metódussal egyszer hajthat végre utófeldolgozási műveleteket. A Windows PowerShell futtatás csak egyszer hívja meg ezt a metódust.
A BeginProcessing metódus felülbírálása
- Deklarálhatja a System.Management.Automation.Cmdlet.BeginProcessing metódus védett felülbírálást.
Az alábbi osztály egy mintaüzenetet nyomtat ki. Az osztály használatához módosítsa a Parancsmag attribútumban található igét és főnevet, módosítsa az osztály nevét úgy, hogy az az új ige és főnév legyen, majd adja hozzá a szükséges funkciókat a System.Management.Automation.Cmdlet.BeginProcessing metódus felülbírálásához.
[Cmdlet(VerbsDiagnostic.Test, "BeginProcessingClass")]
public class TestBeginProcessingClassTemplate : Cmdlet
{
// Override the BeginProcessing method to add preprocessing
//operations to the cmdlet.
protected override void BeginProcessing()
{
// Replace the WriteObject method with the logic required
// by your cmdlet. It is used here to generate the following
// output:
// "This is a test of the BeginProcessing template."
WriteObject("This is a test of the BeginProcessing template.");
}
}
A ProcessRecord metódus felülbírálása
- Deklarálhatja a System.Management.Automation.Cmdlet.ProcessRecord metódus védett felülbírálást.
Az alábbi osztály egy mintaüzenetet nyomtat ki. Ennek az osztálynak a használatához módosítsa a Parancsmag attribútumban található ige és főnév értékét, módosítsa az osztály nevét úgy, hogy az tükrözze az új igét és főnevet, majd adja hozzá a szükséges funkciókat a System.Management.Automation.Cmdlet.ProcessRecord metódus felülbírálásához.
[Cmdlet(VerbsDiagnostic.Test, "ProcessRecordClass")]
public class TestProcessRecordClassTemplate : Cmdlet
{
// Override the ProcessRecord method to add processing
//operations to the cmdlet.
protected override void ProcessRecord()
{
// Replace the WriteObject method with the logic required
// by your cmdlet. It is used here to generate the following
// output:
// "This is a test of the ProcessRecord template."
WriteObject("This is a test of the ProcessRecord template.");
}
}
Az EndProcessing metódus felülbírálása
- Deklarálhatja a System.Management.Automation.Cmdlet.EndProcessing metódus védett felülbírálást.
Az alábbi osztály egy mintát nyomtat ki. Az osztály használatához módosítsa a Parancsmag attribútumban található igét és főnevet, módosítsa az osztály nevét úgy, hogy az az új ige és főnév legyen, majd adja hozzá a szükséges funkciókat a System.Management.Automation.Cmdlet.EndProcessing metódus felülbírálásához.
[Cmdlet(VerbsDiagnostic.Test, "EndProcessingClass")]
public class TestEndProcessingClassTemplate : Cmdlet
{
// Override the EndProcessing method to add postprocessing
//operations to the cmdlet.
protected override void EndProcessing()
{
// Replace the WriteObject method with the logic required
// by your cmdlet. It is used here to generate the following
// output:
// "This is a test of the BeginProcessing template."
WriteObject("This is a test of the EndProcessing template.");
}
}
Lásd még:
System.Management.Automation.Cmdlet.BeginProcessing
System.Management.Automation.Cmdlet.EndProcessing