如何测试对象是否具有特定属性? [英] How can you test if an object has a specific property?
本文介绍了如何测试对象是否具有特定属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何测试对象是否具有特定属性?
How can you test if an object has a specific property?
感谢我能做到...
$members = Get-Member -InputObject $myobject
然后foreach
通过$members
,但是有没有函数可以测试对象是否有特定的属性?
and then foreach
through the $members
, but is there a function to test if the object has a specific property?
附加信息:问题是我正在导入两种不同类型的 CSV 文件,一种具有两列,另一种具有三列.我无法让支票与属性"一起使用,只能与NoteProperty"一起使用......无论有什么区别
Additional Info: The issue is I'm importing two different sorts of CSV file, one with two columns, the other with three. I couldn't get the check to work with "Property", only with "NoteProperty" ... whatever the difference is
if ( ($member.MemberType -eq "NoteProperty" ) -and ($member.Name -eq $propertyName) )
推荐答案
喜欢这个吗?
[bool]($myObject.PSobject.Properties.name -match "myPropertyNameToTest")
这篇关于如何测试对象是否具有特定属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文