What would the C# code be to create a (service) method to return an object (ViewModel for DDL) using AutoMapper and provide the two field names as parameters?
DDL is for a Drop Down List:
public class DDLitems {
public string text {get;set;}
public string value {get;set}
}
My horrible pseudo C# code idea: (yea no idea how to do this yet):
public IList<DDLobject> AutoMapDDLvalue( IList<object> source,
type objectClass.textFieldName,
type objectClass.valueFieldName)
{
var EntityRepository = new EntityRepository();
Mapper.CreateMap<source.type, DDLobject>()
.ForMember(dest => dest.text,
opt => opt.MapFrom(src => src.objectClass.textFieldName))
.ForMember(dest => dest.value,
opt => opt.MapFrom(src => src.objectClass.valueFieldName));
return Mapper.Map<IList<source>, IList<DDLobject>>(EntityRepository.Get());
}
I just thought that the field types would need to be converted to string. I guess we could add a generic .ToString() to each.