こんにちは、ジェネリックを使用するクラスを作成しました。コードは次のとおりです。
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 関数の周りにワッパーを作成しようとしている私のケースです。そして、それが最初の 2 つの方法の目的です。
私の問題は、ターゲットにもう1つのプロパティがある場合があることです.これは私のソースです:
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 の具象型が必要です。