그 인터페이스를 구현
List<IInfrastructureEntity>.
TestRepository
(아래), I는 일반
TEntity
을 복용하고에 , 클래스 유형을 결정하고
DataSource
에서 해당 데이터를 가져 오십시오. 대신 각 return 문에서 다음과 같은 컴파일 타임 오류가 발생합니다. 어떤
TEntity
도 반드시
IInfrastructureEntity
을 구현하더라도.
암시 내가 명시 적 변환을 어떻게해야합니까 'System.Collections.Generic.List<TEntity>
'
에 유형 'System.Collections.Generic.List<IInfrastructureEntity>
을'변환 할 수 없습니다?
public class TestRepository<TEntity> : IRepository<TEntity> where TEntity : IInfrastructureEntity
{
public List<TEntity> GetData()
{
TEntity checkType = default(TEntity);
if (checkType is Member) return DataSource.Members;
if (checkType is MenuItem) return DataSource.MenuItems;
if (checkType is CRAWApplication) return DataSource.CRAWApplications;
if (checkType is CRAWEntitlement) return DataSource.CRAWEntitlements;
if (checkType is FOXGroup) return DataSource.FOXGroups;
throw new NotSupportedException(checkType.ToString() + " is not yet supported");
}
public List<TEntity> FindBy(Expression<Func<TEntity, bool>> predicate)
{
return GetData().AsQueryable().Where(predicate);
}
}
오우! 그게 그게 맞습니까? 고맙습니다. – Joe
@Joe 오신 것을 환영합니다! 내가 도왔다 니 기쁘다. – Christos