Guest User

Untitled

a guest
Aug 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Pass a constrained type to a method
  2. public static List<ListItem> ListItemListFromEnum(Type t)
  3. {
  4. ...
  5. }
  6.  
  7. public static List<ListItem> ListItemListFromEnum(Enum e)
  8. {
  9. Type t = e.GetType();
  10. }
  11.  
  12. public static List<ListItem> ListItemsListFromEnum<T>() where T:Enum
  13.  
  14. public static List<ListItem> ListItemListFromEnum(Type t)
  15. {
  16. if (!t.IsEnum)
  17. {
  18. throw new ArgumentException("Type must be an enumeration", "t");
  19. }
  20. }
  21.  
  22. public static List<ListItem> ListItemListFromEnum<T>()
  23. {
  24. if (!typeof(T).IsEnum)
  25. {
  26. throw new ArgumentException("Type must be an enumeration", "t");
  27. }
  28. }
  29.  
  30. public static List<ListItem> ListItemListFromEnum(Type t)
  31. {
  32. if (!t.IsEnum)
  33. {
  34. throw new ArgumentException("The type passed in must be an enum type.");
  35. }
  36.  
  37. // ...
  38. }
Add Comment
Please, Sign In to add comment