Custom Exception Using Enumerator Instead of String

base can only call static methods

   
namespace MyCustomApp
{
    public class InvalidReportOperationException : Exception
    {
        public InvalidReportOperationException(InvalidReportOpertaionOptions option, int? id ) : base(MessageGenerator(option,id))
        {
          
        }
       
        private static string MessageGenerator(InvalidReportOpertaionOptions option, int? id)
        {

            switch (option)
            {
                case InvalidReportOpertaionOptions.Item:
                    {
                        var idString = id.HasValue ? $" : {id} " : " ";
                        return ($"Item{idString}Not Found");
                    }
                case InvalidReportOpertaionOptions.InversedDateRange:
                    return "Start Date Cannot Be Greater Than End Date";

                default:
                    return "Report Error";      

            }

        }
    }
    public enum InvalidReportOpertaionOptions
    {
        Item =1,
        InversedDateRange=2

    }
}

Related Posts

Comments are closed.