I had wrote this codes:
public interface IUser
{
string Username { get; set; }
string Password { get; set; }
IList<IRole> Roles { get; set; }
}
public interface IRole
{
string Name { get; set; }
IList<IUser> Users { get; set; }
}
public class User : IUser
{
public string Username { get; set; }
public string Password { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IList<Role> Roles { get; set; }
}
public class Role : IRole
{
public string Name { get; set; }
public IList<User> Users { get; set; }
}
I think in logic there is no problem. Because User class is type of IUser interface, and Role class is type of IRole interface too. But it doesn't compile. Actually Compiler doesn't recognize that classes are type of their interfaces. The question is why is this happening and what to do?
Role does not implement interface member IRole.Users. Users cannot implement IRole.Users because it does not have the matching return type of IList<IRole>.