您好我有創建使用generics.Here是我的代碼類:編譯器並沒有看到我的具體類型
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的具體類型。
我已經爲他們添加了使用語句,但是resharper告訴我他們可以被刪除,因爲他們不是用戶。
如何讓編譯器看到GetUpcomingLessons_Result和UpcommingLessonsDTO是具體類型?
編輯
這裏是我的情況下,我想創建一個圍繞Autommapper的映射功能wapper。 而前兩種方法是什麼。
我的問題是,我在我的目標有一個更property.This的情況下,是我源:
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。
具體類型? *你認爲這意味着什麼? –
我創建的類 – aleczandru
請顯示所有代碼 – Serghei