【发布时间】:2015-02-21 22:55:25
【问题描述】:
主要问题很简单。我创建了一个 c# dll,用作访问解决方案的插件。将错误信息从 dll 返回到解决方案的正确 OO 设计模式是什么?
我知道我曾经对用 C 编写的 dll 使用 SetLastError 之类的东西,但这似乎不是 OO 模式的最佳解决方案。基本设置是我有一个用 VBA 编写的类,它调用 dll 中的方法。这些方法根据它们是否有效返回 true 或 false。但是,如果方法返回 false,我希望能够获得有关失败性质的更多信息。
`
interface IMyClass
{
bool MyMethod();
}
class MyClass: IMyClass
{
public bool MyMethod()
{
if(DoSomething() != null)
{
return true;
}
else
{
return false;
}
}
private someDataType DoSomething()
{
try
{
Something;
return someDataType;
}
catch(SomeException e)
{
//how do I return this information
return null;
}
}
}
`
【问题讨论】: