Click here to Skip to main content
12,351,441 members (33,662 online)
Click here to Skip to main content
Articles » Languages » C# » General » Alternatives
Add your own
alternative version

Tagged as

Stats

8.7K views
Posted

Passing Enum type as a parameter

, 2 Oct 2011 CPOL
I think the start is wrong... we can pass types as parameters.A method like this:void ShowName(Type type){ Console.WriteLine(type.FullName);}can be called as:ShowName(typeof(object));or as this:ShowName(someObject.GetType());If you are trying to say that we can't...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

30 Aug 2011
jarvisa
"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...
23 Aug 2011
Ed Hellyer Evosis LLC
5 alternatives  
Cycling through (looping around) enum lists.
24 Aug 2011
Daniel Gidman
I think the compile time force for a little enum enforcement would look something like this... (excuse the bad syntax, doing it from memory)private T GetPreviousEnum(this T currentlySelectedEnum) where T: structStackOverflow has a good question and answer in relation to it here.[^].
30 Aug 2011
Narf the Mouse
Seeing as I "researched" your code and the code on StackOverflow for my own implementations, I figure I should post this - It's a default enumerator for any Enum. Free to use, free to copy; just attribute alike :) : /// /// Created based on the "Passing Enum type...

License

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

Share

About the Author

Paulo Zemek
Engineer Microsoft Corporation
United States United States
I started to program computers when I was 11 years old, as a hobbist, programming in AMOS Basic and Blitz Basic for Amiga.
At 12 I had my first try with assembler, but it was too difficult at the time. Then, in the same year, I learned C and, after learning C, I was finally able to learn assembler (for Motorola 680x0).
Not sure, but probably between 12 and 13, I started to learn C++. I always programmed "in an object oriented way", but using function pointers instead of virtual methods.

At 15 I started to learn Pascal at school and to use Delphi. At 16 I started my first internship (using Delphi). At 18 I started to work professionally using C++ and since then I've developed my programming skills as a professional developer in C++ and C#, generally creating libraries that help other developers do they work easier, faster and with less errors.

Now I just started working as a Senior Software Engineer at Microsoft.

Want more info or simply want to contact me?
Take a look at: http://paulozemek.azurewebsites.net/
Or e-mail me at: paulozemek@outlook.com

Codeproject MVP 2012, 2015 & 2016
Microsoft MVP 2013-2014 (now I work at Microsoft so I can't be a Microsoft MVP anymore)

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 2 Oct 2011
Article Copyright 2011 by Paulo Zemek
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid