c# - Visual Studio |如果忘记在摘要中声明异常则通知

标签 c# visual-studio visual-studio-2017 resharper

我有以下 FooClass。共有三种方法,其中两种可以抛出 exception。 如果仅在 HasException 方法中声明,则可以抛出 exception。 当您有大型项目时,您可能会忘记在摘要中描述异常

如果我忘记声明一个exception,是否可以扫描解决方案?在我的示例中,缺少四个 exceptions(声明)。

public class FooClass
{
    public FooClass()
    {
        HasException();

        HasNoException();

        HasChildException();
    }

    /// <summary>
    /// This method does not throw an <see cref="Exception"/>.
    /// </summary>
    public void HasNoException()
    {

    }

    /// <summary>
    /// This method is throwing an <see cref="Exception"/>.
    /// </summary>
    /// <exception cref="Exception">Is immediately thrown.</exception>
    public void HasException()
    {
        throw new Exception();
    }

    /// <summary>
    /// This method can throwing an <see cref="Exception"/> from a method it calls.
    /// </summary>
    public void HasChildException()
    {
        //throws an exception
        HasException();

        //throws also an exception
        int.Parse("foo");
    }
}

工具提示

hasexception parse

这应该是如何描述该方法的示例

/// <summary>
/// This method can throwing an <see cref="Exception"/> from a method it calls.
/// </summary>
/// <exception cref="Exception"></exception>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="FormatException"></exception>
/// <exception cref="OverflowException"></exception>
public void HasChildException()
{
    //throws an exception
    HasException();

    //throws also an exception
    int.Parse("foo");
}

preview

最佳答案

执行此操作的一种方法(不是唯一的方法)是使用名为“Exceptional”的 Resharper 扩展。转到 Resharper > Extension manager > 搜索“Exceptional”,安装并重新启动 Visual Studio。之后,所有可能抛出异常但未记录的地方都将带有下划线,并且使用 alt-enter 您将能够自动创建异常文档模板。对于您的示例,它会找到您提到的所有情况甚至更多(构造函数本身,它也可以抛出所有异常)。

关于c# - Visual Studio |如果忘记在摘要中声明异常则通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47197234/

相关文章:

vb.net - 插入图像到Excel

python - 如何在 Visual Studio IronPython 项目中配置导入路径

visual-studio - 托管调试助手 'FatalExecutionEngineError' 0xc0000005

visual-studio-2017 - AnkhSVN未在Visual Studio 2017中显示

C# 使应用程序支持插件,运行多个实例,可能吗?

c# - 如何在内部使用 IronPython 引用自包含的 C# 类库项目 (Visual Studio 2010)

c# - 我应该在 #if (DEBUG) 中包装对 Debugger.Log() 的调用吗?

visual-studio-2017 - 为什么 Visual Studio 2017 使用 TLS 1.0?

c# - 这段代码在做什么?

c# - 返回包含 2 个子类的 IQueryable