|
| 1 | +namespace Common.BasicHelper.Core.Exceptions; |
| 2 | + |
| 3 | +public enum ErrorCodes |
| 4 | +{ |
| 5 | + Undefined, |
| 6 | + CB0017, |
| 7 | + CB0027, |
| 8 | + CB0033, |
| 9 | + CB0034, |
| 10 | +} |
| 11 | + |
| 12 | +public class ErrorCodesHelper |
| 13 | +{ |
| 14 | + public static string GetExceptionMessage |
| 15 | + ( |
| 16 | + ErrorCodes ec, |
| 17 | + string? attachment = null, |
| 18 | + string? functionName = null, |
| 19 | + string? parameterName = null, |
| 20 | + string? inputFormatRequirements = null, |
| 21 | + string? inputLengthRequirements = null |
| 22 | + ) |
| 23 | + => ec switch |
| 24 | + { |
| 25 | + ErrorCodes.CB0017 => $"Only use `{functionName}` function for same types. {attachment}", |
| 26 | + ErrorCodes.CB0027 => $"Parameter `{parameterName}` not found. {attachment}", |
| 27 | + ErrorCodes.CB0033 => $"Error input format. {inputFormatRequirements} {attachment}", |
| 28 | + ErrorCodes.CB0034 => $"Error input length. {inputLengthRequirements} {attachment}", |
| 29 | + _ => $"Message for {ec} not found. {attachment}", |
| 30 | + }; |
| 31 | +} |
| 32 | + |
| 33 | +public static class ErrorCodesExtensions |
| 34 | +{ |
| 35 | + public static string BuildMessage |
| 36 | + ( |
| 37 | + this ErrorCodes ec, |
| 38 | + string? attachment = null, |
| 39 | + string? functionName = null, |
| 40 | + string? parameterName = null, |
| 41 | + string? inputFormatRequirements = null, |
| 42 | + string? inputLengthRequirements = null |
| 43 | + ) |
| 44 | + => ErrorCodesHelper.GetExceptionMessage |
| 45 | + ( |
| 46 | + ec, |
| 47 | + attachment, |
| 48 | + functionName, |
| 49 | + parameterName, |
| 50 | + inputFormatRequirements, |
| 51 | + inputLengthRequirements |
| 52 | + ); |
| 53 | +} |
0 commit comments