is possible in c# create generic function first parameter enum (one of several has generic guess) , second parameter forced value enum selected first parameter? understand generics has used can't think of how write such expression, or if it's possible.
edit: added code example know code example doesn't work illustrates little in direction thinking.
public list<int> call<enumvalue>(type enumtype, enumvalue enumvalue) enumvalue : enum.getvalues(typeof(enumtype)) { // }
i don't think possible have compile-time constraint that. best run-time check:
public list<int> call<tenum>(type enumtype, tenum enumvalue) { if(!enumtype.isassignablefrom(typeof(tenum))) throw new argumentexception(); // } update: although i'm not sure why need pass type, if has be same type other parameter anyway. couldn't rid of first parameter?
public list<int> call<tenum>(tenum enumvalue) { type enumtype = typeof(tenum); // }
Comments
Post a Comment