나는 foo 클래스가
public abstract class Foo
{
protected int[,] bar;
public abstract Point test(int a, int b);
}
그리고 프로그램에는 foo
.
class inheritedClass : Foo
{
// ...
}
그리고 DLL에서 다른 클래스를로드하고 List<Foo>
상속 된 모든 클래스를 저장 하는에 추가하고 싶습니다 Foo
. 내가 어떻게 해? 이제 다음이 있습니다.
try
{
DLL = Assembly.LoadFile(name);
Type type = DLL.GetType("DLL.customObject");
var obj = Activator.CreateInstance(type);
// Even when [obj] is not null, [newObj] is always null
newObj = obj as Foo;
}
catch
{
return false;
}
여기 내 DLL이 있습니다.
namespace DLL
{
public class customObject : Foo
{
// ...
}
public abstract class Foo
{
protected int[,] bar;
public abstract Point test(int a, int b);
}
}
내가 이해했듯이 DLL의 클래스를 사용자 정의 클래스의 하위 항목으로 만들고 싶습니다. C #에서는 불가능합니다. 클래스 코드에 액세스 할 수없는 경우 상속 계층 구조를 변경할 수 없습니다. List<object>
개체를 저장 하는 데 사용하는 것이 좋습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다