If you have the PublishedPropertyType, then you can search the PropertyValueConverters collection for it.
Here's a quick snippet of how you could do it...
// however you get the `propertyType`?
var converter = Current.PropertyValueConverters.FirstOrDefault(x => x..IsConverter(propertyType) == true);
if (converter != null)
{
// do your thang!
}
Note, using Umbraco.Core.Composing.Current really depends on where/how you are coding this. If it's in a controller, then you're better using Dependency Injection - injecting the PropertyValueConverterCollection instance instead.
Thanks - that's definitely advanced my cause a bit - using IsConverter(type) to find the matching Converter is on the track of what I'm trying to achieve - but I'm needing to do this for Umbraco-v7.
However, IsConverter() requires a PublishedPropertyType, and I currently only have a PropertyType and its Alias which I fetched using the ContentTypeService - not sure how to get from the PropertyType to the PublishedPropertyType
It's been a while since I'd looked at v7's APIs, trying to recall how we did this for the original Nested Content package - found some bits and pieces.
To get the PublishedPropertyType, you first need the PublishedContentType, which you can do as follows...
var publishedContentType = PublishedContentType.Get(PublishedItemType.Content, contentTypeAlias);
Cheers, that helped a lot, and I got to where I wanted to be, only to hit a problem that requires me to go and re-think this thing.
Basically, I was building a custom backoffice tool to list the property editors on a known composition, and the valuetypes they return. I was working my way towards using GetPropertyValueType(PublishedPropertyType) of the PropertyValueConverter as it seemed to be documented as an interface method, but that was a no-go. So I then dug into the API docs, and it seems that's not actually the case (not sure why the discrepancy) so I can't use that approach to find the converted type ...this needs some more thought.
Find PropertyValueConverter from PropertyEditor Alias ?
I have a PropertyType and its PropertyEditor Alias, and I now want to find the PropertyValueConverter that returns its value - is that possible?
Hi MB,
If you have the
PublishedPropertyType
, then you can search thePropertyValueConverters
collection for it.Here's a quick snippet of how you could do it...
Note, using
Umbraco.Core.Composing.Current
really depends on where/how you are coding this. If it's in a controller, then you're better using Dependency Injection - injecting thePropertyValueConverterCollection
instance instead.(If you'd like more info about Dependency Injection in Umbraco, there are details in the docs: https://our.umbraco.com/documentation/reference/using-ioc/)
Hope this helps?
Cheers,
- Lee
Thanks - that's definitely advanced my cause a bit - using IsConverter(type) to find the matching Converter is on the track of what I'm trying to achieve - but I'm needing to do this for Umbraco-v7.
I suspect I could do something similar using:
However, IsConverter() requires a PublishedPropertyType, and I currently only have a PropertyType and its Alias which I fetched using the ContentTypeService - not sure how to get from the PropertyType to the PublishedPropertyType
Hi MB,
It's been a while since I'd looked at v7's APIs, trying to recall how we did this for the original Nested Content package - found some bits and pieces.
To get the
PublishedPropertyType
, you first need thePublishedContentType
, which you can do as follows...Then from there, you can get the
PublishedPropertyType
...Once you have the
publishedPropertyType
, then you can find out the value converter for it.Hope this helps?
Cheers,
- Lee
Cheers, that helped a lot, and I got to where I wanted to be, only to hit a problem that requires me to go and re-think this thing.
Basically, I was building a custom backoffice tool to list the property editors on a known composition, and the valuetypes they return. I was working my way towards using GetPropertyValueType(PublishedPropertyType) of the PropertyValueConverter as it seemed to be documented as an interface method, but that was a no-go. So I then dug into the API docs, and it seems that's not actually the case (not sure why the discrepancy) so I can't use that approach to find the converted type ...this needs some more thought.
is working on a reply...