如果我有一个接受从 IUser 派生的泛型类型的类,我该如何避免此错误消息
无法将类型隐式转换
ElimCMS.Service.Users.someclass<ElimCMS.DataModel.Users.User>
为ElimCMS.Service.Users.Isomeclass<ElimCMS.DataModel.Users.IUser>
. 存在显式转换(您是否缺少演员表?)
例子
public interface Isomeclass<TUser>
where TUser : class, IUser
{
string test(TUser user);
TUser returnUser();
}
public class someclass<TUser> : Isomeclass<TUser>
where TUser : class, IUser, new()
{
public string test(TUser user)
{
string email = user.EMail;
user.EMail = "changed:" + email;
return email;
}
public TUser returnUser()
{
throw new NotImplementedException();
}
}
Isomeclass<ElimCMS.DataModel.Users.IUser> servicetest = new someclass<ElimCMS.DataModel.Users.User>();