I have several generic methods that use the typeof
operator to determine the type of mapper class to create. Eventually this is going to get out of hand.
Can anyone suggest a better way to handle this? I have been reading up a bit and it seems like an abstract factory pattern or IOC would be a good pattern to use. I'm not familiar with IOC. Can someone provide an opinion on which would be better in this scenario?
internal UpdateStudentDocumentRequest MapDocToUpdateDocumentRequest<T>(T doc)
{
Type docType = typeof(T);
//V1
if
(
docType == typeof(IndV1201314Model) ||
docType == typeof(IndV1201415Model) ||
docType == typeof(DepV1201415Model)
)
{ return new V1DocMapper<Models.Verification.V1Base>().MapV1ToUpdateStudentDocumentRequest(doc as Models.Verification.V1Base); }
//V3
if
(
docType == typeof(IndV3201314Model) ||
docType == typeof(IndV3201415Model) ||
docType == typeof(DepV3201415Model)
)
{ return new V3DocMapper<Models.Verification.V3Base>().MapV3ToUpdateStudentDocumentRequest(doc as Models.Verification.V3Base); }
//FASchol
if (docType == typeof(FAScholModel))
{return new FAScholMapper().MapFAScholToUpdateStudentDocumentRequest(doc as FAScholModel);}
return new UpdateStudentDocumentRequest();
}