【发布时间】:2013-07-18 03:30:24
【问题描述】:
您好,我创建了一个使用泛型的类。这是我的代码:
public class RegisterMappings : IRegisterMappings
{
public virtual void CreateMap<TFrom, TTo>()
{
Mapper.CreateMap<TFrom, TTo>();
}
public void PostRegisterMappings()
{
Mapper.AssertConfigurationIsValid();
}
public void CreateGetUpcommingLessons<GetUpcomingLessons_Result , UpcomingLessonDTO>()
{
Mapper.CreateMap<GetUpcomingLessons_Result, UpcomingLessonDTO>().ForMember(dest => dest.TeacherOfficialName, opt => opt.Ignore());
}
}
在我的例子中,编译器似乎没有将 GetUpcomingLessons_Result 和 UpcommingLessonsDTO 视为具体类型。
我已经为它们添加了 using 语句,但 resharper 告诉我它们可以被删除,因为它们不是用户。
如何让编译器看到 GetUpcomingLessons_Result 和 UpcommingLessonsDTO 是具体类型?
编辑
这是我的案例,我试图围绕 Autommapper 的 Mapper 函数创建一个 wapper。 这就是前两种方法的用途。
我的问题是我的目标还有一个属性。这是我的来源:
public partial class GetUpcomingLessons_Result
{
public string CourseName { get; set; }
public string ModuleName { get; set; }
public Nullable<int> ModuleInstanceId { get; set; }
public int StudentAssignmentId { get; set; }
public int StudentAssignmentInstanceId { get; set; }
public Nullable<System.DateTime> EventDate { get; set; }
public Nullable<System.DateTime> StartTime { get; set; }
public Nullable<System.DateTime> EndTime { get; set; }
public string TeacherLastName { get; set; }
public string TeacherMiddleName { get; set; }
public string TeacherGender { get; set; }
public Nullable<int> LessonNumber { get; set; }
public string LocationName { get; set; }
}
这是我的目的地:
public class UpcomingLessonDTO
{
public string CourseName { get; set; }
public string ModuleName { get; set; }
public int? ModuleInstanceId { get; set; }
public int StudentAssignmentId { get; set; }
public int StudentAssignmentInstanceId { get; set; }
public DateTime? EventDate { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public string TeacherLastName { get; set; }
public string TeacherMiddleName { get; set; }
public string TeacherGender { get; set; }
public int? LessonNumber { get; set; }
public string LocationName { get; set; }
// calculated fields
public string TeacherOfficialName { get; set; }
}
我需要告诉映射器忽略 TeacherOfficialName 名称。直到现在这很容易,我会这样写:
Mapper.CreateMap<GetUpcomingLessons_Result, UpcomingLessonDTO>().ForMember(dest => dest.TeacherOfficialName, opt => opt.Ignore());
但是在创建包装器之后,我需要为这种情况创建另一个方法,这就是为什么我需要 GetUpcomingLessons_Result 和 UpcomingLessonDTO 的具体类型。
【问题讨论】:
-
具体类型? 你认为这意味着什么?
-
我创建的类
标签: c# .net generics automapper