我在跟踪方法等的.net库中使用了smartinspect.但是对于发布配置,我想避免部署smartinspect以及跟踪代码中的所有内容的开销.有没有一种简单的方法来实现这一点,而不是每次调用方法时都使用编译器指令?
示例代码:
public bool OpenDocument(string srcFile)
{
SiExportWordSession.EnterMethod(this, "OpenDocument");
try
{
SiExportWordSession.LogString("srcFile", srcFile);
try
{
_doc = new Document(srcFile);
return true;
}
catch (Exception e)
{
SiExportWordSession.LogException(e);
ErrorName = e.GetType().Name;
ErrorMessage = e.Message;
return false;
}
}
finally
{
SiExportWordSession.LeaveMethod(this, "OpenDocument");
}
}
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是为smartinspect创建一个包装器,它可以调用smartinspect或什么也不做,具体取决于发布配置.但这不会让我摆脱尝试最终的构造.有没有更好的方法来解决这个问题?