Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwheeler committed Jan 31, 2024
1 parent 1e4937a commit 5999c91
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 442 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ To support dynamic parameters, the following elements must be included in the cm

### Interface

[System.Management.Automation.IDynamicParameters](/dotnet/api/System.Management.Automation.IDynamicParameters).
This interface provides the method that retrieves the dynamic parameters.
[System.Management.Automation.IDynamicParameters][03]. This interface provides the method that
retrieves the dynamic parameters.

For example:

`public class SendGreetingCommand : Cmdlet, IDynamicParameters`

### Method

[System.Management.Automation.IDynamicParameters.GetDynamicParameters](/dotnet/api/System.Management.Automation.IDynamicParameters.GetDynamicParameters).
This method retrieves the object that contains the dynamic parameter definitions.
[System.Management.Automation.IDynamicParameters.GetDynamicParameters][04]. This method retrieves
the object that contains the dynamic parameter definitions.

For example:

Expand Down Expand Up @@ -107,14 +107,18 @@ public class SendGreetingCommandDynamicParameters
}
```

For a complete example of a cmdlet that supports dynamic parameters, see [How to Declare Dynamic Parameters](./how-to-declare-dynamic-parameters.md).
For a complete example of a cmdlet that supports dynamic parameters, see
[How to Declare Dynamic Parameters][01].

## See also

[System.Management.Automation.IDynamicParameters](/dotnet/api/System.Management.Automation.IDynamicParameters)
- [System.Management.Automation.IDynamicParameters][03]
- [System.Management.Automation.IDynamicParameters.GetDynamicParameters][04]
- [How to Declare Dynamic Parameters][01]
- [Writing a Windows PowerShell Cmdlet][02]

[System.Management.Automation.IDynamicParameters.GetDynamicParameters](/dotnet/api/System.Management.Automation.IDynamicParameters.GetDynamicParameters)

[How to Declare Dynamic Parameters](./how-to-declare-dynamic-parameters.md)

[Writing a Windows PowerShell Cmdlet](./writing-a-windows-powershell-cmdlet.md)
<!-- link references -->
[01]: ./how-to-declare-dynamic-parameters.md
[02]: ./writing-a-windows-powershell-cmdlet.md
[03]: /dotnet/api/System.Management.Automation.IDynamicParameters
[04]: /dotnet/api/System.Management.Automation.IDynamicParameters.GetDynamicParameters
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ title: How to Declare Dynamic Parameters
---
# How to Declare Dynamic Parameters

This example shows how to define dynamic parameters that are added to the cmdlet at runtime. In this example, the `Department` parameter is added to the cmdlet whenever the user specifies the `Employee` switch parameter. For more information about dynamic parameters, see [Cmdlet Dynamic Parameters](./cmdlet-dynamic-parameters.md).
This example shows how to define dynamic parameters that are added to the cmdlet at runtime. In this
example, the `Department` parameter is added to the cmdlet whenever the user specifies the
`Employee` switch parameter. For more information about dynamic parameters, see
[Cmdlet Dynamic Parameters][02].

## To define dynamic parameters

1. In the cmdlet class declaration, add the [System.Management.Automation.Idynamicparameters](/dotnet/api/System.Management.Automation.IDynamicParameters) interface as shown.
1. In the cmdlet class declaration, add the [System.Management.Automation.Idynamicparameters][03]
interface as shown.

```csharp
public class SendGreetingCommand : Cmdlet, IDynamicParameters
```

2. Call the [System.Management.Automation.Idynamicparameters.Getdynamicparameters*](/dotnet/api/System.Management.Automation.IDynamicParameters.GetDynamicParameters) method, which returns the object in which the dynamic parameters are defined. In this example, the method is called when the `Employee` parameter is specified.
1. Call the [System.Management.Automation.Idynamicparameters.Getdynamicparameters*][04] method,
which returns the object in which the dynamic parameters are defined. In this example, the method
is called when the `Employee` parameter is specified.

```csharp
public object GetDynamicParameters()
Expand All @@ -31,7 +37,8 @@ This example shows how to define dynamic parameters that are added to the cmdlet
private SendGreetingCommandDynamicParameters context;
```

3. Declare a class that defines the dynamic parameters to be added. You can use the attributes that you used to declare the static cmdlet parameters to declare the dynamic parameters.
1. Declare a class that defines the dynamic parameters to be added. You can use the attributes that
you used to declare the static cmdlet parameters to declare the dynamic parameters.

```csharp
public class SendGreetingCommandDynamicParameters
Expand All @@ -49,7 +56,9 @@ This example shows how to define dynamic parameters that are added to the cmdlet

## Example

In this example, the `Department` parameter is added whenever the user specifies the `Employee` parameter. The `Department` parameter is an optional parameter, and the ValidateSet attribute is used to specify the allowed arguments.
In this example, the `Department` parameter is added whenever the user specifies the `Employee`
parameter. The `Department` parameter is an optional parameter, and the ValidateSet attribute is
used to specify the allowed arguments.

```csharp
using System;
Expand Down Expand Up @@ -126,10 +135,14 @@ namespace SendGreeting

## See Also

[System.Management.Automation.Runtimedefinedparameterdictionary](/dotnet/api/System.Management.Automation.RuntimeDefinedParameterDictionary)

[System.Management.Automation.Idynamicparameters.Getdynamicparameters*](/dotnet/api/System.Management.Automation.IDynamicParameters.GetDynamicParameters)

[Cmdlet Dynamic Parameters](./cmdlet-dynamic-parameters.md)

[Windows PowerShell SDK](../windows-powershell-reference.md)
- [System.Management.Automation.RuntimeDefinedParameterDictionary][05]
- [System.Management.Automation.IDynamicParameters.GetDynamicParameters*][04]
- [Cmdlet Dynamic Parameters][02]
- [Windows PowerShell SDK][01]

<!-- link references -->
[01]: ../windows-powershell-reference.md
[02]: cmdlet-dynamic-parameters.md
[03]: xref:System.Management.Automation.IDynamicParameters
[04]: xref:System.Management.Automation.IDynamicParameters.GetDynamicParameters
[05]: xref:System.Management.Automation.RuntimeDefinedParameterDictionary
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,5 @@ The following example shows the `DynamicParameters` element of the `Encoding` dy
```

<!-- link references -->
[01]: ./how-to-add-parameter-information.md
[02]: /dotnet/api/microsoft.powershell.commands.filesystemcmdletproviderencoding
[01]: how-to-add-parameter-information.md
[02]: xref:Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding
Loading

0 comments on commit 5999c91

Please sign in to comment.