Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Pass a constrained type to a method
- public static List<ListItem> ListItemListFromEnum(Type t)
- {
- ...
- }
- public static List<ListItem> ListItemListFromEnum(Enum e)
- {
- Type t = e.GetType();
- }
- public static List<ListItem> ListItemsListFromEnum<T>() where T:Enum
- public static List<ListItem> ListItemListFromEnum(Type t)
- {
- if (!t.IsEnum)
- {
- throw new ArgumentException("Type must be an enumeration", "t");
- }
- }
- public static List<ListItem> ListItemListFromEnum<T>()
- {
- if (!typeof(T).IsEnum)
- {
- throw new ArgumentException("Type must be an enumeration", "t");
- }
- }
- public static List<ListItem> ListItemListFromEnum(Type t)
- {
- if (!t.IsEnum)
- {
- throw new ArgumentException("The type passed in must be an enum type.");
- }
- // ...
- }
Add Comment
Please, Sign In to add comment