【发布时间】:2010-10-07 09:15:08
【问题描述】:
我尝试使用 $function:foo 值和 get-item function:foo。所有尝试都成功修改了临时函数对象,但在重新分配给存储函数时缺少附加属性(通过 $function:foo = ... 或 set-item function:foo ...)。
这是我尝试的结果(全部失败):
设置
#1
$=>set-item 函数:f $f -force $=>$函数:foo |通用汽车* >#2
$=>$函数:f = $f $=>$函数:foo |通用汽车* >#3
$=>$f = 获取项目函数:foo $=>$f |通用汽车 类型名称:System.Management.Automation.FunctionInfo 名称 MemberType 定义 ---- ---------- ---------- 等于方法 System.Boolean Equals(Object obj) GetHashCode 方法 System.Int32 GetHashCode() GetType 方法 System.Type GetType() ToString 方法 System.String ToString() PSDrive NoteProperty System.Management.Automation.PSDriveInfo PSDrive=Function PIsContainer NoteProperty System.Boolean PIsContainer=False PSPath NoteProperty System.String PSPath=Microsoft.PowerShell.Core\Function::foo PSProvider NoteProperty System.Management.Automation.ProviderInfo PSProvider=Microsoft.... CmdletBinding 属性 System.Boolean CmdletBinding {get;} CommandType 属性 System.Management.Automation.CommandTypes CommandType {get;} DefaultParameterSet 属性 System.String DefaultParameterSet {get;} 定义属性 System.String 定义 {get;} 描述 属性 System.String 描述 {get;set;} 模块属性 System.Management.Automation.PSModuleInfo 模块 {get;} ModuleName 属性 System.String ModuleName {get;} 名称属性 System.String 名称 {get;} 选项属性 System.Management.Automation.ScopedItemOptions 选项 {get;set;} 参数 属性 System.Collections.Generic.Dictionary`2[[System.String, mscorli... ParameterSets 属性 System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Man... ScriptBlock 属性 System.Management.Automation.ScriptBlock ScriptBlock {get;} 可见性属性 System.Management.Automation.SessionStateEntryVisibility Visibi... $=>$f = $f | add-member note 属性栏 barValue -pass $=>$f |通用汽车* 类型名称:System.Management.Automation.FunctionInfo 名称 MemberType 定义 ---- ---------- ---------- bar NoteProperty System.String bar=barValue $=>设置项功能:foo $f $=>$函数:foo |通用汽车* >不知道我做错了什么。似乎在重新分配时这些属性被剥离了。那是对的吗?定义的行为?我没有看到任何文档说 FunctionInfo 对象或 ScriptBlocks 被异常处理。这是语言的某个深奥角落吗?
【问题讨论】:
标签: powershell properties