65.9K
CodeProject is changing. Read more.
Home

Passing Enum type as a parameter

starIconstarIconstarIconstarIconstarIcon

5.00/5 (4 votes)

Aug 30, 2011

CPOL
viewsIcon

7950

"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 currentlySelectedEnum)
{
	...

	return (T)enums.GetValue(index);
}