开发者

How to convert cmdlet parameter (which is string) to any other type

I want to pass parameter of custom type to my cmdlet. I declare parameter like this:

[Parameter(Position = 1)]
public StoreIdParameter Identity { get; set; }

But when I run cmdlet with parameter (like this: Get-Store VS) I get an exception:

Cannot bind parameter 'Identity'. Cannot convert the "VS" value of type "System.String" to type "R.Management.StoreIdParameter".

I created a constructor of StoreIdParameter, which accepts String but it didn't help. Should it be some type convertor from string to my type?开发者_JS百科


I have found a solution. That was my mistake - I had constructor accepting string argument only in base class. I have added constructor to derived class (StoreIdParameter) with string argument and Powershell could create an instance of this class by calling proper constructor

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜