MiscHelper.cs 706 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace GreenTree.Nachtragsmanagement.Core.Helper
  7. {
  8. public static class MiscHelper
  9. {
  10. /// <summary>
  11. /// Trys to parse a string to valid integer and returns NULL if it fails
  12. /// </summary>
  13. /// <param name="item">String value.</param>
  14. /// <returns>Parsed string.</returns>
  15. public static int? TryGetInt(this string item)
  16. {
  17. if (String.IsNullOrEmpty(item)) return null;
  18. int i;
  19. var success = int.TryParse(item, out i);
  20. return success ? (int?)i : (int?)null;
  21. }
  22. }
  23. }