PowerShell では、いくつかのパラメーターが動的なオートコンプリート動作をしています。たとえば、パラメーター Name を Get-Process します。TAB を使用して、すべてのプロセスを繰り返すことができます。
この動作を PSCmdlet で使用したいと考えています。
しかし、問題は、静的なオートコンプリート値でこれを行う方法しか知らないことです。例を参照してください。
public class TableDynamicParameters
{
[Parameter]
[ValidateSet("Table1", "Table2")]
public string[] Tables { get; set; }
}
これがネイティブの powershell http://blogs.technet.com/b/heyscriptingguy/archive/2014/03/21/use-dynamic-parameters-to-populate-list-of-printer-namesでどのように行われるかの例を次に示します。 aspx
それ は@bouvierrにthxで動作します
public string[] Tables { get; set; }
public object GetDynamicParameters()
{
if (!File.Exists(Path)) return null;
var tableNames = new List<string>();
if (TablesCache.ContainsKey(Path))
{
tableNames = TablesCache[Path];
}
else
{
try
{
tableNames = DbContext.GetTableNamesContent(Path);
tableNames.Add("All");
TablesCache.Add(Path, tableNames);
}
catch (Exception e){}
}
var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary();
runtimeDefinedParameterDictionary.Add("Tables", new RuntimeDefinedParameter("Tables", typeof(String), new Collection<Attribute>() { new ParameterAttribute(), new ValidateSetAttribute(tableNames.ToArray()) }));
return runtimeDefinedParameterDictionary;
}