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 BeginProcessing metódus felülbírálása

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

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

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

System.Management.Automation.Cmdlet.ProcessRecord

Windows PowerShell-parancsmag írása