【问题标题】:Error when Method and Namespace is same name方法和命名空间同名时出错
【发布时间】:2019-07-10 09:36:41
【问题描述】:

我有 2 个项目,都使用相同版本的 AutoMapper。所以这两个项目都需要使用这段代码来配置配置文件

 public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            //CreateMap goes here
        }       
    }

如你所见,我将从 AutoMapper 继承类 Profile。但是问题发生在另一个项目上。

这个项目的命名空间是Profile.API。那么发生了什么是我收到错误'Profile' is a namespace but is used like a type

这是我的课程AutoMapperProfile的完整代码

using AutoMapper;


namespace Profile.API.Infrastructure.AutoMapper
{
    public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            //CreateMap goes here
        }       
    }
}

需要建议

【问题讨论】:

  • 完全限定基类:AutoMapperProfile : Fully.Qualified.Profile
  • 不能,仍然错误@ErikPhilips
  • 问题已解决,只需将文件夹从“AutoMapper”重命名为另一个名称。然后可以使用AutoMapperProfile : AutoMapper.Profile

标签: c# .net-core automapper


【解决方案1】:

给 Automapper using 一个别名:

using AM = AutoMapper;

namespace Profile.API.Infrastructure.AutoMapper
{
    public class AutoMapperProfile : AM.Profile
    {
        public AutoMapperProfile()
        {
            //CreateMap goes here
        }
    }
}

【讨论】:

    猜你喜欢
    • 2020-05-02
    • 2022-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多