gpt4 book ai didi

powershell - 可以使用Get-Member检查集合的方法和属性,而不是检查集合项(默认值)吗?

转载 作者:行者123 更新时间:2023-12-03 00:59:04 24 4
gpt4 key购买 nike

假设$coll是对象的集合。 $coll | Get-Member显示集合项的成员。我不知道它是如何工作的,无论它是检查第一个项目然后停止还是显示所有项目成员的并集。但是,它会检查项目,而不是收集对象本身。通常,这就是我们想要的。

但是,如果我想检查馆藏本身怎么办?我仍然可以这样做还是必须使用.NET反射功能?

最佳答案

愚蠢的我,当然可以。我只需要使用-InputObject参数,而不是管道-Get-Member -InputObject $coll而不是$coll | Get-Member

C:\WINDOWS\System32> $x = @([pscustomobject]@{a = 1})
C:\WINDOWS\System32> $x|Get-Member


TypeName: System.Management.Automation.PSCustomObject

Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
a NoteProperty int a=1


C:\WINDOWS\System32> Get-Member -InputObject $x


TypeName: System.Object[]

Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Add Method int IList.Add(System.Object value)
Address Method System.Object&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a...
Clear Method void IList.Clear()
Clone Method System.Object Clone(), System.Object ICloneable.Clone()
CompareTo Method int IStructuralComparable.CompareTo(System.Object other, System.Collections.ICo...
Contains Method bool IList.Contains(System.Object value)
CopyTo Method void CopyTo(array array, int index), void CopyTo(array array, long index), void...
Equals Method bool Equals(System.Object obj), bool IStructuralEquatable.Equals(System.Object ...
Get Method System.Object Get(int )
GetEnumerator Method System.Collections.IEnumerator GetEnumerator(), System.Collections.IEnumerator ...
GetHashCode Method int GetHashCode(), int IStructuralEquatable.GetHashCode(System.Collections.IEqu...
GetLength Method int GetLength(int dimension)
GetLongLength Method long GetLongLength(int dimension)
GetLowerBound Method int GetLowerBound(int dimension)
GetType Method type GetType()
GetUpperBound Method int GetUpperBound(int dimension)
GetValue Method System.Object GetValue(Params int[] indices), System.Object GetValue(int index)...
IndexOf Method int IList.IndexOf(System.Object value)
Initialize Method void Initialize()
Insert Method void IList.Insert(int index, System.Object value)
Remove Method void IList.Remove(System.Object value)
RemoveAt Method void IList.RemoveAt(int index)
Set Method void Set(int , System.Object )
SetValue Method void SetValue(System.Object value, int index), void SetValue(System.Object valu...
ToString Method string ToString()
Item ParameterizedProperty System.Object IList.Item(int index) {get;set;}
IsFixedSize Property bool IsFixedSize {get;}
IsReadOnly Property bool IsReadOnly {get;}
IsSynchronized Property bool IsSynchronized {get;}
Length Property int Length {get;}
LongLength Property long LongLength {get;}
Rank Property int Rank {get;}
SyncRoot Property System.Object SyncRoot {get;}


C:\WINDOWS\System32>

关于powershell - 可以使用Get-Member检查集合的方法和属性,而不是检查集合项(默认值)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58677043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com