关于异常:在C#中继承构造函数文档?

Inherit constructor documentation in C#?

我在C中有一个自定义异常类:

1
public class InformationException : Exception {}

当然,这不起作用,因为这个异常没有构造函数。

只是确定一下:我真的要自己添加吗?:

1
2
3
4
5
6
public class InformationException : Exception
{
    public InformationException() : base() {}
    public InformationException(string message): base(message) {}
    public InformationException(string message, Exception innerException) : base(message, innerException) {}
}

但是为了使类真正有用,我必须添加文档:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class InformationException : Exception
{
    /// <summary>
    /// Initializes a new instance of the System.Exception class.
    /// </summary>
    public InformationException() : base() {}

    /// <summary>
    /// Initializes a new instance of the System.Exception class with a specified error message.
    /// </summary>
    /// <param name="message"> The message that describes the error.</param>
    public InformationException(string message): base(message) {}

    /// <summary>
    /// Initializes a new instance of the System.Exception class with a specified error message and a reference to the inner exception that is the cause of this exception.
    /// </summary>
    /// <param name="message"> The error message that explains the reason for the exception.</param>
    /// <param name="innerException">The exception that is the cause of the current exception, or a null reference
    /// (Nothing in Visual Basic) if no inner exception is specified.</param>
    public InformationException(string message, Exception innerException) : base(message, innerException) {}
}

我现在要重复的是:

1
2
3
4
5
6
7
public class ClientException : InformationException { }

public class BusinessRuleException : InformationException { }

public class InvisibleException : Exception { }

public class ProgrammerException : InvisibleException { }

在过去的三年里,我没有错过任何关于C的变化?这仍然是继承类的预期方式?

更新:哎呀,原来您还必须提供受保护的构造函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class InformationException : Exception
{
    public InformationException() : base() {}
    public InformationException(string message): base(message) {}

    /// <summary>
    /// Initializes a new instance of the System.Exception class with serialized data.
    /// </summary>
    /// <param name="info">The System.Runtime.Serialization.SerializationInfo that holds the serialized
    /// object data about the exception being thrown.</param>
    /// <param name="context">The System.Runtime.Serialization.StreamingContext that contains contextual
    /// information about the source or destination.</param>
    /// <exception cref="System.ArgumentNullException">The info parameter is null</exception>
    /// <exception cref="System.Runtime.Serialization.SerializationException">The class name is null or System.Exception.HResult is zero (0).</exception>
    protected InformationException(SerializationInfo info, StreamingContext context);

    protected Exception(SerializationInfo info, StreamingContext context): base(info, context) {}
    public InformationException(string message, Exception innerException) : base(message, innerException) {}
}


如本答案所述,您可以使用GhostDoc