I am going to develop a membership system that would have 7+ levels of user role with many other user feature. For example having 3rd level permission for a city and having 5th level permission for another city.
Is it possible to compare 2 objects as if they have numerical values? For example comparing a user's role against a certain level role.
if (objUser.role >= userRole.userLevel3){
//do something
}
The permission rules are way complicated than I briefly explained. So comparing users' role with minimum afford possible is my goal. I am the lead developer of the project and it is my job to provide an easy to use membership system for less experienced developers.
Please consider this question as thinking out loud, I am open to ideas/discussions.
C# lets you overload comparison operators, so this is definitely possible. You can overload the pair of operators <
and >=
(they must be overloaded in pairs), like this:
class AccessLevel {
...
public static bool operator <=(AccessLevel x, AccessLevel y) {
...
}
public static bool operator >(AccessLevel x, AccessLevel y) {
...
}
}