Created
September 13, 2014 21:42
-
-
Save dhcgn/2f0d4b4d1f08088c438e to your computer and use it in GitHub Desktop.
C# PSCmdlet RuntimeDefinedParameter usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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