PowerTip of the Day-Discover Hidden Object Members
原文地址:http://app.en25.com/e/es.aspx?s=1403&e=4513&elq=cc07fc74696e467fa7306ce10ab2a4d0
原文:
Get-Member is a great cmdlet to discover object members, but it will not show everything:
"Hello" | Get-Member
You should add -force to really see a complete list of object members:
"Hello" | Get-Member -force
One of the more interesting hidden members is called PSTypeNames and lists the types this object was derived from:
"Hello".PSTypeNames
These types become important when PowerShell formats the object. The first type in that PSTypeNames-list that can be found in PowerShell’s internal type database is used to format the information. To prove that point, you should check out what happens if you manipulate that information:
PS> $a = "Hello"
PS> $a.pstypenames.Clear()
PS> $a
PS> $a -eq 'Hello'
True
Without PSTypeNames, PowerShell no longer knows how to format the string and will display empty space instead.
翻译:
Get-Member用来查看对象成员十个不错的cmdlet,但是它不会把所有的属性都显示出来:
"Hello" | Get-Member
如果要看到一个完整的成员列表的话需要加上-force
比较有意思的一个隐藏成员是PSTypeNames,通过下面的方法就可以列出一个对象的所有类型:
"Hello".PSTypeNames
当powershell格式化一个对象的时候这些类型是很重要的。在PSTypeNames-list(在powershell的内部类型数据库中)的第一个类型就是用来格式化信息的。为了证明这一点,可以尝试一下以下的代码:
PS> $a = "Hello"
PS> $a.pstypenames.Clear()
PS> $a
PS> $a -eq 'Hello'
True
如果没有PSTypeNames,Powershell就不会知道如何格式化一个字符串并且只会显示空结果。
笔记:
学习获取隐藏的member方法。
看上去这些成员就跟注册表一样,轻易还是不要动它们。
---------------------------------------------------------------
aspnetx的BI笔记系列索引:
使用SQL Server Analysis Services数据挖掘的关联规则实现商品推荐功能
---------------------------------------------------------------