c# - 如何设计流畅的界面(用于异常处理)?

标签 c# dsl fluent-interface

我正在审查代码库的一部分,我发现异常处理部分非常困惑。我想用更优雅的东西代替它。然后我想,如果我能有一个流畅的界面来帮助我注册一些异常列表的策略,并让 ExceptionHandlingManager 为我完成剩下的工作,这可能不是一个坏主意:

这是一个如何工作的示例:

For<TException>.RegisterPolicy<TPolicy>(a lambda expression that describes the detail);

但我完全迷失了。我走在正确的轨道上吗?当我们想要设计这样一个流畅的界面时,最好的方法是什么?我的意思是,如果流畅的界面是 DSL 的一部分,那么设计流畅的界面就像设计语言一样吗?


我所说的这个模块是一个通用模块,负责所有未处理的异常。它是一个像这样的一百行模块:

if(exp.GetType()==typeof(expType1))
{
    if(exp.Message.Include("something went bad"))
    // do list of things things like perform logging to database 
    // and translating/reporting it to user
}
else if (exp.GetType()==typeof(expType2))
{
    //do some other list of things...
    ...
}

最佳答案

我编写了一个简单流畅的异常处理程序。它很容易扩展。您可以在这里查看:http://thetoeb.wordpress.com/2013/12/09/fluent-exceptionhandling/也许可以根据您的目标进行定制。

关于c# - 如何设计流畅的界面(用于异常处理)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9400472/

相关文章:

C# 加速字符串?

c# - Linux下使用MonoDevelop的项目中如何使用Console.ReadLine()

c# - 如何选择整个 DataGrid 表格行并使用 WPF 单击按钮将其删除?

c++ - Boost Spirit 在服务器应用程序上实现小型单行 DSL

elasticsearch - 在Elasticsearch中排序聚合?

haskell - 在 Haskell 中建模异构图

c++ - 在流畅的界面中避免不必要的模板实例化

c# - 使用datagridview更新数据库中的数据

entity-framework - EF6.0 “The relationship could not be changed because one or more of the foreign-key properties is non-nullable”

c# - 如何通过 Fluent 接口(interface)开发 sql 查询生成器?