gpt4 book ai didi

c# - 从派生类在 powershell 中构建自定义类型

转载 作者:太空宇宙 更新时间:2023-11-03 11:30:23 24 4
gpt4 key购买 nike

我正在尝试使用我自己的基础对象和列表中的一些特殊功能来构建一个特定列表。它作为 exe 运行良好。但是当我尝试在 powershell 中导入等效的 dll 时不起作用。

    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

我无法实例化 myTest.tata,但类型似乎已声明。看来问题出在

 public class tata: List<stuff>

powershell 中的某些东西无法解释这一行

有没有人遇到同样的问题并解决了这个问题?

最佳答案

除了警告从未使用过 val 之外,您发送的代码对我来说工作正常。所以我不得不忽略警告

    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

它给了我 tata 作为输出你能检查一下你发送的内容是否真的是问题所在吗?

关于c# - 从派生类在 powershell 中构建自定义类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7996031/

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