문제

For example I have a PSObject transaction with two properties: id and transactionName , so that it looks like: transaction { id: 123 transactionName : tranName1 }

and I want to return the id of the transaction if its name is tranName1.

It looks to me that in powershell scripts, we can simply do:

if $transaction.transactionName -eq tranName return $transaction.id

however in c# it will give error since it cannot recognize the property by name... any ideas how to do it in c#?

도움이 되었습니까?

해결책

Try something like this:

psobjectvariable.Properties["transactionName"].Value

다른 팁

Here's something that I didn't expect to work, but it did.

dynamic x = psobjectvariable;
Console.Write(x.transactionName);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top