This is how I see a possible solution and will be what I will add to my pull request. These methods are the ones causing issues:
protected virtual object MapString(string stringValue, Type targetType, string pageContextId, Localization localization)
...
if (targetType == typeof(RichText))
{
return new RichText(stringValue);
}
and
protected virtual object MapRichText(RichTextData richTextData, Type targetType, Localization localization)
...
if (targetType == typeof(RichText))
{
return new RichText(fragments);
}
After looking deeper at the code, a potential solution would be to replace those if's with these respectively:
On the MapString method:
if (typeof(RichText).IsAssignableFrom(targetType))
{
var richText = targetType.CreateInstance(stringValue);
return richText;
}
On the MapRichText method:
if (typeof(RichText).IsAssignableFrom(targetType))
{
var customRichText = targetType.CreateInstance(fragments);
return customRichText;
}
RichText richText = new RichText(fragments);
return richText.ToString();
So unless anybody has a reason for this not to be feasible, i.e. extending RichText models, I will go ahead and create a new (issue) and Pull Request to try to get my code in place.
Let me know your thoughts.
**Update: Issue has been reported and pull request submitted: **
https://github.com/sdl/dxa-web-application-dotnet/issues/78
RichText
in the first place?