文件夹结构揭示[错误?] CS0246:“类型或命名空间名称‘IAsyncRepository<>’”找不到”

发布于 2025-01-15 19:50:43 字数 974 浏览 2 评论 0 原文

RE:DotNet 6.0 和 VS Community 2022(64 位)- CurrentVersion 17.1.1

此代码会导致编译器错误 CS0246:

using GloboTicket.TicketManagement.Domain.Entities;

namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
    public interface IOrderRepository: IAsyncRepository<Order>
    {
    }
}

以下代码不会(请注意使用前缀“Persistence”来引用 IAsyncRepository):

using GloboTicket.TicketManagement.Domain.Entities;

namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
    public interface IOrderRepository: Persistence.IAsyncRepository<Order>
    {
    }
}

为什么有这个必要吗? IAsyncRepository 和 IOrderRepository 是同一文件夹中的兄弟姐妹 - 即同一命名空间中!

无需“持久性”即可使用引用。如果在基类型“IAsyncRepository”中删除了“where T : class”前缀:

namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
    public interface IAsyncRepository<T> where T : class
    {
      /...
    }
}

RE: DotNet 6.0 and VS Community 2022 (64-bit) - CurrentVersion 17.1.1

This code results in a compiler error CS0246:

using GloboTicket.TicketManagement.Domain.Entities;

namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
    public interface IOrderRepository: IAsyncRepository<Order>
    {
    }
}

This following code does not (note the use of the prefix "Persistence." to refer to IAsyncRepository):

using GloboTicket.TicketManagement.Domain.Entities;

namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
    public interface IOrderRepository: Persistence.IAsyncRepository<Order>
    {
    }
}

Why is this needed? IAsyncRepository and IOrderRepository are siblings in the same folder - i.e., in the same namespace!

The reference can be used without the "Persistance." prefix if the "where T : class" is deleted in the base type "IAsyncRepository":

namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
    public interface IAsyncRepository<T> where T : class
    {
      /...
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文