问题描述
当我在.NET的框架在C#中使用另一个对象,我可以通过使用指令节省了大量的输入。
When I use another object in the .net-Framework in C# I can save a lot of typing by using the using directive.
using FooCompany.Bar.Qux.Assembly.With.Ridiculous.Long.Namespace.I.Really.Mean.It;
...
var blurb = new Thingamabob();
...
那么,有没有办法在PowerShell中做类似的东西?我访问了很多.NET对象,我不开心不必键入
So is there a way in Powershell to do something similiar? I'm accessing a lot of .net objects and am not happy of having to type
$blurb = new-object FooCompany.Bar.Qux.Assembly.With.Ridiculous.Long.Namespace.I.Really.Mean.It.Thingamabob;
所有的时间。
all the time.
推荐答案
看看这个博客文章一对夫妇多年前:http://blogs.msdn.com/richardb/archive/2007/02/21/add-types-ps1-poor-man-s-using-for-powershell.aspx
Check out this blog post from a couple years ago: http://blogs.msdn.com/richardb/archive/2007/02/21/add-types-ps1-poor-man-s-using-for-powershell.aspx
基本上我做的是抓取组件平凡的类型,然后写一个使用添加会员添加它们(结构化的方式)来我所关心的对象构造。
Basically what I do is crawl the assembly for nontrivial types, then write a "constructor" that uses Add-Member add them (in a structured way) to the objects I care about.
也看到这个后续职位: http://richardberg.net/blog/?p=38
See also this followup post: http://richardberg.net/blog/?p=38
这篇关于相当于C#的"使用"在PowerShell中的关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!