似乎我遇到的问题尚未在任何主题中涉及,或者至少我还没有找到任何主题。
我正在尝试使用 C# 程序集,其中构造函数需要一个枚举器类型参数,该参数也在类中定义。
namespace Utils.Translate
{
/// <summary>
/// Converts ASCII to EBCDIC or vice-versa
/// </summary>
public class AsciiEbcdic
{
/// <summary>
/// The enumerator CharSet2Use determines which target character set to use.
/// </summary>
public enum CharSet2Use
{
A2E = 0, //ASCII to EBCDIC
E2A // EBCDIC to ASCII
};
// Constructor
public AsciiEbcdic( CharSet2Use whichSet )
{
}
}
}
加载程序集没问题:
[System.Reflection.Assembly]::LoadFile( "EbcdicAscii.dll" )
但是,当我尝试实例化它时,
$nameSpace = "Utils.Translate.EbcdicAscii"
$var = New-Object $nameSpace( [Utils.Translate.EbcdicAscii+Char2Set2Use]::A2E )
我得到错误:
Unable to find type [Utils.Translate.EbcdicAscii+Char2Set2Use]: make sure that the assembly containing this type is loaded.
我还尝试了以下方法:
$var = New-Object $nameSpace -ArgumentList [Utils.Translate.EbcdicAscii+Char2Set2Use]::A2E
我得到错误:
New-Object : Cannot find type [Utils.Translate.EbcdicAscii]: make sure the assembly containing this type is loaded.
还尝试将参数传递为 A2E, 'A2E', 0, '0' 无济于事。
有没有办法通过在类中定义的枚举器数据类型来实例化这个对象?