tôi có hệ thống phân cấp sau thừa kế:Giao tiếp kế thừa với IDisposable?
public interface IRepository<T> : IDisposable
{
void Add(T model);
void Update(T model);
int GetCount();
T GetById(int id);
ICollection<T> GetAll();
}
public interface IAddressRepository : IRepository<Address>
{
}
Và mã này:
var adrs = new Address[]{
new Address{Name="Office"}
};
using (IAddressRepository adrr = new AddressRepository())
foreach (var a in adrs)
adrr.Add(a);
Tuy nhiên, mã này không biên dịch. Nó cung cấp cho tôi thông báo lỗi này:
Error 43
'Interfaces.IAddressRepository': type used in a using statement must be
implicitly convertible to 'System.IDisposable'
Tuy nhiên, cha mẹ của IAddressRepository
được kế thừa từ IDisposable
.
Điều gì đang xảy ra ở đây? Làm cách nào để tôi biên dịch mã?
Tôi không thể sao chép số này –
Chúng tôi có thể thấy lớp 'AddressRepository' của bạn - điều này sẽ hoạt động nếu nó đang triển khai đúng cách (mặc dù có một lỗi khác xảy ra nếu không!). –
Bạn có thể hiển thị định nghĩa của AddressRepository không? Ngay bây giờ, bạn chỉ đang hiển thị IAddressRepository. – mbeckish