dba123
asked on
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<IRole>'
We have this class defined:
namespace VU.Business.Entities
{
public class KuDbRoleProvider : IRoleProvider
{
public KuDbRoleProvider();
public IEnumerable<IRole> GetDefaultRoles();
public IRole GetRoleByName(string roleName);
public IRole New(string roleName);
public IEnumerable<IRole> RetrieveAllRoles();
}
}
And in another class I'm trying to implement and call the RetrieveAllRoles() and put it into some sort of collection which I tried making an array:
class KURoleProvider : RoleProviderBase
{
public override Configuration.Roles.Role[] GetRoles()
{
KuDbRoleProvider roleProvider;
BusinessInterfaces.Securit y.IRole[] kuRoles;
kuRoles = roleProvider.RetrieveAllRo les();
....
I can't figure out how to get this working. Here is my error:
Cannot implicitly convert type 'System.Collections.Generi c.IEnumera ble<Busine ssInterfac es.Securit y.IRole>' to 'BusinessInterfaces.Securi ty.IRole'. An explicit conversion exists (are you missing a cast?)
namespace VU.Business.Entities
{
public class KuDbRoleProvider : IRoleProvider
{
public KuDbRoleProvider();
public IEnumerable<IRole> GetDefaultRoles();
public IRole GetRoleByName(string roleName);
public IRole New(string roleName);
public IEnumerable<IRole> RetrieveAllRoles();
}
}
And in another class I'm trying to implement and call the RetrieveAllRoles() and put it into some sort of collection which I tried making an array:
class KURoleProvider : RoleProviderBase
{
public override Configuration.Roles.Role[]
{
KuDbRoleProvider roleProvider;
BusinessInterfaces.Securit
kuRoles = roleProvider.RetrieveAllRo
....
I can't figure out how to get this working. Here is my error:
Cannot implicitly convert type 'System.Collections.Generi
IRole[] is Array. As IEnumerable<T>, they are both IEnumerable. But you cannot convert IEnumerable<T> to Array implicitly. You can declare kuRoles as IEnumerable<IRole>, that will work.
ASKER
why would you use an IEnumerable in the first place to get a list of roles when you can just shove it into a frigging generic list or array? I don't see why whoever implemented this with an Enumerable.
ASKER
It is pretty obvious, that I need to implement all the methods in the IRoleProvider which it looks like KuDbRoleProvider has not done yet. It's just stubbed out. I don't need to create a new class, I just need to finish the implementation on KuDbRoleProvider methods for IRoleProvider it looks like. I just don't get why anyone would use IEnumerable to get a list of the roles from our DAL when you can just push it into an array in the first place.
ASKER
nevermind I guess I was looking at some meta data of that class. So here's the implementation of RetrieveAll
public IEnumerable<IRole> RetrieveAllRoles()
{
List<IRole> roles = new List<IRole>();
using (IDataReaderEnumerable<DAL .Role> dalRoles = DAL.Role.RetrieveAll())
foreach (DAL.Role dalRole in dalRoles)
roles.Add(new Role(dalRole));
return roles;
}
Why the hell would you use IEnumerable in this case? it's returning a generic list in the first place that can be sorted so why would you do that? and what's this IDataReaderEnumerable...we ird, I've never used this before. I didn't implement this method and the person who did is out right now.
public IEnumerable<IRole> RetrieveAllRoles()
{
List<IRole> roles = new List<IRole>();
using (IDataReaderEnumerable<DAL
foreach (DAL.Role dalRole in dalRoles)
roles.Add(new Role(dalRole));
return roles;
}
Why the hell would you use IEnumerable in this case? it's returning a generic list in the first place that can be sorted so why would you do that? and what's this IDataReaderEnumerable...we
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
List<KuDbRoleProvider >