File size: 1,901 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#nullable enable
namespace System.Management.Automation.Subsystem
{
/// <summary>
/// Implementation of 'Get-PSSubsystem' cmdlet.
/// </summary>
[Cmdlet(VerbsCommon.Get, "PSSubsystem", DefaultParameterSetName = AllSet)]
[OutputType(typeof(SubsystemInfo))]
public sealed class GetPSSubsystemCommand : PSCmdlet
{
private const string AllSet = "GetAllSet";
private const string TypeSet = "GetByTypeSet";
private const string KindSet = "GetByKindSet";
/// <summary>
/// Gets or sets a concrete subsystem kind.
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = KindSet, ValueFromPipeline = true)]
public SubsystemKind Kind { get; set; }
/// <summary>
/// Gets or sets the interface or abstract class type of a concrete subsystem.
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = TypeSet, ValueFromPipeline = true)]
public Type? SubsystemType { get; set; }
/// <summary>
/// ProcessRecord implementation.
/// </summary>
protected override void ProcessRecord()
{
switch (ParameterSetName)
{
case AllSet:
WriteObject(SubsystemManager.GetAllSubsystemInfo(), enumerateCollection: true);
break;
case KindSet:
WriteObject(SubsystemManager.GetSubsystemInfo(Kind));
break;
case TypeSet:
WriteObject(SubsystemManager.GetSubsystemInfo(SubsystemType!));
break;
default:
throw new InvalidOperationException("New parameter set is added but the switch statement is not updated.");
}
}
}
}
|