I have the following method which takes a type of class as a parameter:
public void test(Type proType){ } I currently have a large if else which looks like:
if(proType == typeof(Class)){} As there is about ten this looks untidy.
I tried turning this in to a switch but couldn't get it to work.
Is there any better practice to this or away to get a switch statement to work?
switch (proType) { case typeof(ClassName): break; } "A constant value required"
The function is been called like test(typeof(class))
So the aim is i have a Big object which contains many small classes.
The typeof(class) switch/if statement allows me to decide what container to go in to get the objects out.
test(Type proType)? How is it called? Are you doing something liketest(typeof(someObj))? How about encapsulating the code for each case in a known interface method on each of the types you are testing?