2011-11-03 60 views
2

我想用我自己的基礎對象和我的列表中的一些特殊功能來構建特定列表。 它作爲一個EXE很好。但是,當我嘗試在PowerShell中導入等效的DLL時不起作用。在派生類的PowerShell中構建自定義類型

add-type @" 
using System.Collections.Generic; 
namespace myTest 
{ 
    public class stuff 
    { 
     public int val; 
     public stuff(int val) 
     { 
     this.val = val; 
     } 
    } 
    public class tata : List<stuff> 
    { 
    int val ; 
    .. 
    } 
} 
"@ 

而調用類:

$example = new-object myTest.stuff ->Works 
$example2 = new-object myTest.tata ->Does not work 

我不能intanciate myTest.tata但類型似乎聲明。 看來,問題來自

public class tata: List<stuff> 

東西在PowerShell中無法解釋這一行

是否有人有同樣的問題,解決這個問題?

回答

2

您發送的代碼對我來說工作得很好,除了警告val從不使用。因此,我不得不IgnoreWarnings

add-type " 
using System.Collections.Generic; 
namespace myTest 
{ 
    public class stuff 
    { 
     public int val; 
     public stuff(int val) 
     { 
      this.val = val; 
     } 
    } 
    public class tata : List<stuff> 
    { 
     int val; 
    } 
} " -IgnoreWarnings 

$example = new-object myTest.stuff(1) 
$example2 = new-object myTest.tata 
$example2.GetType().Name 

它給了我塔塔作爲輸出 你可以檢查您發送的內容實際上是什麼讓你的問題?