This small article is geared toward those of you who are currently using Lee Kelleher’s Ditto extension in their Umbraco projects. I won’t be explaining what Ditto or Umbraco is in this post, but I may create a post later about both.
So again, back to those of you who do use Ditto, sometimes you may run into the scenario where you want to access the current content node that is being mapped from a TypeConverter. In my situation, I had multinode treepicker, and I wanted to access the node that was picked and being mapped at the time. For instance I had an Article content item that was picked, and I needed to run some custom logic on the population/mapping of that object.
What is not in the documentation at this time of this writing is a trick in which you can grab the context from the TypeCoverter as such:
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
// Grab current context and content item
var dittoContext = (DittoTypeConverterContext)context;
var content = (IPublishedContent)context.Instance;
// Insert any other logic to return the appropriate value
Hopefully this is quick and painless help for those of you looking for this answer.