Created
February 24, 2023 09:51
-
-
Save coenm/b281a0a25188d632efd7cfe236814bc6 to your computer and use it in GitHub Desktop.
Exception according to SonarCloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace A.B.C; | |
| using System; | |
| using System.Net; | |
| using System.Runtime.Serialization; | |
| [Serializable] | |
| public class MyException : Exception | |
| { | |
| public MyException(HttpStatusCode statusCode, string? message) | |
| : base(message ?? $"{statusCode} ({(int)statusCode})") | |
| { | |
| StatusCode = statusCode; | |
| } | |
| // Without this constructor, deserialization will fail | |
| protected MyException(SerializationInfo info, StreamingContext context) | |
| : base(info, context) | |
| { | |
| StatusCode = (HttpStatusCode)info.GetInt32(nameof(StatusCode)); | |
| } | |
| public HttpStatusCode StatusCode { get; } | |
| public override void GetObjectData(SerializationInfo info, StreamingContext context) | |
| { | |
| info.AddValue(nameof(StatusCode), (int)StatusCode); | |
| base.GetObjectData(info, context); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment