小编k0d*_*nd0的帖子

如何标记方法将无条件抛出?

有没有办法装饰一个会进行一些日志记录的方法,然后无条件地抛出异常,如此?

我有这样的代码:

void foo(out int x)
{
  if( condition() ) { x = bar(); return; }

  // notice that x is not yet set here, but compiler doesn't complain

  throw new Exception( "missed something." );
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试这样写,我会遇到问题:

void foo(out int x)
{
  if( condition() ) { x = bar(); return; }

  // compiler complains about x not being set yet

  MyMethodThatAlwaysThrowsAnException( "missed something." );
}
Run Code Online (Sandbox Code Playgroud)

有什么建议?谢谢.

.net c# attributes exception-handling

10
推荐指数
1
解决办法
2540
查看次数

如何为每个项目配置设置不同的项目依赖项?

我想拥有不同的项目依赖项,具体取决于我目前正在构建的项目配置.

例如,我不想在Release配置中构建和链接SomeTestLib.vcproj,但我想在Debug中构建并链接到它.

一种解决方案,即sorta工作,是使用条件编译宏:

#ifdef DEBUG  
#pragma comment( lib, "SomeTestLib" )  
#endif
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,调试器和IntelliSense不适用于SomeTestLib.
是否有我可以使用的.sln或.vcproj hack?
谢谢.

solution vcproj visual-studio

6
推荐指数
1
解决办法
4286
查看次数