I should cast one class into Generic Interface because of some requirements. But I am having ReSharper warning "suspicious cast there is no type in the solution which is inherited from both". In run time, it cause run time error.
I should do this because I am using reflection so I desperetly need this cast. My code as below. Any support appreceated.
ScreenShot below
namespace ConsoleB2B
{
public interface IEntitySubMultiLang
{
int Id { get; set; }
}
public interface IRepo<TEntity> where TEntity : class, IEntitySubMultiLang
{
void Add(TEntity item);
}
public class GenericRepo<TEntity> : IRepo<TEntity> where TEntity : class, IEntitySubMultiLang
{
public void Add(TEntity item)
{
}
}
public class Entry: IEntitySubMultiLang
{
public int Id { get; set; }
}
public class Class1
{
// Error occurs in this line
IRepo<IEntitySubMultiLang> _r = (IRepo<IEntitySubMultiLang>)new GenericRepo<Entry>();
}
}
Aucun commentaire:
Enregistrer un commentaire