pszczyg

EnumSpeed_04

Sep 15th, 2021
486
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static class InvoicePaymentMethodExtensions
  2.     {
  3.         public static bool IsUndefined_WithEnumIsDefined(this InvoicePaymentMethod paymentMethod)
  4.         {
  5.             if (paymentMethod == InvoicePaymentMethod.Undefined)
  6.             {
  7.                 return true;
  8.             }
  9.  
  10.             var isDefined = Enum.IsDefined(typeof(InvoicePaymentMethod), paymentMethod);
  11.             return !isDefined;
  12.         }
  13.  
  14.         public static bool IsUndefined_WithComparingAllValidValuesDirectly(this InvoicePaymentMethod paymentMethod)
  15.         {
  16.             if (paymentMethod == InvoicePaymentMethod.Undefined)
  17.             {
  18.                 return true;
  19.             }
  20.  
  21.             return
  22.                 paymentMethod != InvoicePaymentMethod.AutoGiroNorway &&
  23.                 paymentMethod != InvoicePaymentMethod.Collection &&
  24.                 paymentMethod != InvoicePaymentMethod.Common &&
  25.                 paymentMethod != InvoicePaymentMethod.Combined &&
  26.                 paymentMethod != InvoicePaymentMethod.PrePaid &&
  27.                 paymentMethod != InvoicePaymentMethod.Compensation &&
  28.                 paymentMethod != InvoicePaymentMethod.AvtaleGiro &&
  29.                 paymentMethod != InvoicePaymentMethod.AvtaleGiroSent &&
  30.                 paymentMethod != InvoicePaymentMethod.AvtaleGiroSentNoMsg &&
  31.                 paymentMethod != InvoicePaymentMethod.AvtaleGiroDeleted &&
  32.                 paymentMethod != InvoicePaymentMethod.AvtaleGiroOcr &&
  33.                 paymentMethod != InvoicePaymentMethod.ManualPrint &&
  34.                 paymentMethod != InvoicePaymentMethod.SmallAmount &&
  35.                 paymentMethod != InvoicePaymentMethod.Salary &&
  36.                 paymentMethod != InvoicePaymentMethod.Banker &&
  37.                 paymentMethod != InvoicePaymentMethod.Order &&
  38.                 paymentMethod != InvoicePaymentMethod.Invoice &&
  39.                 paymentMethod != InvoicePaymentMethod.ChequeAgent &&
  40.                 paymentMethod != InvoicePaymentMethod.DebtInsuranceClaim;
  41.         }
  42.  
  43.         private static HashSet<InvoicePaymentMethod> _allDefinedValues;
  44.         static InvoicePaymentMethodExtensions()
  45.         {
  46.             _allDefinedValues = new HashSet<InvoicePaymentMethod>(Enum.GetValues(typeof(InvoicePaymentMethod)).Cast<InvoicePaymentMethod>());
  47.         }
  48.  
  49.         public static bool IsUndefined_WithHashSet(this InvoicePaymentMethod paymentMethod)
  50.         {
  51.             if (paymentMethod == InvoicePaymentMethod.Undefined)
  52.             {
  53.                 return true;
  54.             }
  55.  
  56.             return !_allDefinedValues.Contains(paymentMethod);
  57.         }
  58.     }
RAW Paste Data