Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Passing Enum type as a parameter

, 30 Aug 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
"we cannot pass a Type as a function parameter" ???Yes we can. Just look at the parameter of Enum.GetValues for example._______Generic functions are unnecessary here. Just use Object.GetType to, um, get the type.private Enum GetNextEnum(object currentlySelectedEnum){ Type...
"we cannot pass a Type as a function parameter" ???
 
Yes we can. Just look at the parameter of Enum.GetValues for example.
_______
 
Generic functions are unnecessary here. Just use Object.GetType to, um, get the type.
 
private Enum GetNextEnum(object currentlySelectedEnum)
{
	Type enumList = currentlySelectedEnum.GetType();
_______
 
You could have used the generic type to return a value of the correct type.
 
private T GetNextEnum<t>(T currentlySelectedEnum)
{
	...
 
	return (T)enums.GetValue(index);
}</t>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jarvisa
Software Developer (Senior) Shaw Inspection Systems Ltd
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 30 Aug 2011
Article Copyright 2011 by jarvisa
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid