Skip to content

Instantly share code, notes, and snippets.

@dhcgn
Created September 13, 2014 21:42
Show Gist options
  • Save dhcgn/2f0d4b4d1f08088c438e to your computer and use it in GitHub Desktop.
Save dhcgn/2f0d4b4d1f08088c438e to your computer and use it in GitHub Desktop.
C# PSCmdlet RuntimeDefinedParameter usage
[Cmdlet(VerbsData.Export, "AsQrCode")]
public class ExportAsQrCode : PSCmdlet, IDynamicParameters
{
private static RuntimeDefinedParameterDictionary _staticStroage;
public object GetDynamicParameters()
{
IEnumerable<string> brushes = typeof (Brushes).GetProperties().Select(x => x.Name);
var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary();
var attributes = new Collection<Attribute>
{
new ParameterAttribute
{
HelpMessage = "Brush"
},
new ValidateSetAttribute(brushes.ToArray()),
};
runtimeDefinedParameterDictionary.Add(DarkBrush, new RuntimeDefinedParameter(DarkBrush, typeof (string), attributes));
runtimeDefinedParameterDictionary.Add(LightBrush, new RuntimeDefinedParameter(LightBrush, typeof (string), attributes));
_staticStroage = runtimeDefinedParameterDictionary;
return runtimeDefinedParameterDictionary;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment