在C#中按名称访问PSObject属性 [英] Access PSObject property by name in C#

查看:56
本文介绍了在C#中按名称访问PSObject属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个具有两个属性的PSObject事务:id和transactionName,因此它看起来像:交易 {编号:123transactionName:tranName1}

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

,如果交易名称为tranName1,我想返回交易的ID.

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

在我看来,在Powershell脚本中,我们可以简单地做到:

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

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

但是在c#中会报错,因为它无法按名称识别属性...任何想法如何在c#中做到这一点?

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

推荐答案

尝试如下操作:

psobjectvariable.Properties["transactionName"].Value

这篇关于在C#中按名称访问PSObject属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆