In the following I want to use GetUsersRole but having difficulty with the part shown. I want to compare the Roles values with usersRole, and if Role==usersRole, then UserRole = true, else false.
basically I want to have somehing like this as my result :
user1: true
user2:false
user 3: false
user4: true
depending on usersRole
Class Role
public enum Role
{
User1 = 1,
User2= 2,
User3= 3,
User4= 4
}
I am having a class
private class UserRoleModel
{
public string Role { get; set; }
public bool UserRole { get; set; }
}
and a method
public Role[] UserRoles { get; set; }
private static UserRoleModel[] GetUsersRole(Role[]usersRole)
{
List<UserRoleModel> rolesList = new List<UserRoleModel>();
string[] Roles;
Roles = new string[] { Role.user1.ToString(), Role.User2.ToString(),
Role.user3.ToString(), Role.user4.ToString() };
foreach (var item in Roles)
{
rolesList.Add(new UserRoleModel
{
Role = item,
*UserRole = usersRole.Contains(item)* ////difficulty here
});
}
return rolesList.ToArray();
}
Role, as inRole.user1.ToString(), and where does it come from? What is the actual objective of this code, it seems way too complex and that usually indicates to me that I've made a wrong turn.