I would suggest that this proposed solution be no less convenient than just matching a data source with a code template, as it is now. In fact, I would even say that you will lose flexibility by pushing the template diagram and image information into the database, which will complicate your application.
For example, suppose you have these data sources with attributes (if I understand this correctly):
Document { Author, DateModified }
Picture { Size, Caption, Image }
Song { Artist, Length, AlbumCover }
You can then get one of these data sources in the search results. Each item is rendered differently (an image can be displayed with a preview image attached to the left, or Song can display an album cover, etc.)
. , HTML, , , . , , , , . , , , .
, , , , . , , , , .
, . , , , .
, / , factory . CSS . , XML . , , CSS .
:
, switch:
switch (resultType)
{
case (ResultType.Song):
factory = new SongResultFactory();
template = factory.BuildResult();
break;
. - , switch, , :
IDictionary<ResultType, ResultFactory> TemplateMap;
mapping = new Dictionary<ResultType, ResultFactory>();
mapping.Add(ResultType.Song, new SongResultFactory());
// ... for all mappings.
switch :
template = TemplateMap[resultType].CreateTemplate();
, - - , switch, IDictionary, .
XML , :
<TemplateMap>
<Mapping ResultType="Song" ResultFactoryType="SongResultFactory" />
</TemplateMap>
et. . IDictionary. - , XML , .