Skip to content

DynamicOption PowerShell

Jianyun edited this page Feb 25, 2016 · 9 revisions

DynamicOption class

publicclassDynamicOption{publicOptionCategoryCategory{get;set;}publicOptionTypeExpectedType{get;set;}publicstringName{get;set;}publicboolIsRequired{get;set;}publicIEnumerable<string>PermittedValues{get;set;}}

Dynamic Options are specified for a given category:

ValuePurpose
CategoryThe operation that the dynamic option is for (see [[OptionCategory enum
Typethe data type for the option (see [[OptionType enum
Namethe option name. This is exposed to the end user.
IsRequiredindicates that this option is required for this operation. If not present, the host should not proceed.
PermittedValuesa collection of possible values the user is permitted to specify.
Thefollowing example shows how to define a dynamic option."-Destination"isrequired in Install-Package.publicvoid GetDynamicOptions(stringcategory,Requestrequest){if(request==null){thrownewArgumentNullException("request");}switch((category ??string.Empty).ToLowerInvariant()){case "install":
request.YieldDynamicOption("Destination", Constants.OptionType.Folder, true); break;case "package":// put any options used when searching for packagesrequest.YieldDynamicOption("FilterOnTag",Constants.OptionType.StringArray,false);break;default:
request.Warning(Resources.Messages.UnkownCategory,PackageProviderName,"GetDynamicOptions",category);break;}}

For how to retrieve values of dynamic parameters, please refer to Remarks section.

Clone this wiki locally