The reason you are seeing this behaviour is that IMember / IContent behave differently to the "Published" version.
IContent/IMember's .GetValue method is returning the raw json array string and has no understanding of PropertyValueConverters at this point. If you wanted to get the strongly typed version you would need to get the right property value converter and pass the raw string value in to get the right value out.
I had the realisation last night that you need a PropertyValueConverter and that GetValue<> of IContent/IMember probably doesn't have a PropertyValueConverter for NestedContent (or IEnumerable
But I do see a more than one use case for having a NestedContent property for a member (enrolled in certain entities, documents belonging to a member, etc, etc). So would be great if IMember would have the PropertyValueConverter for IEnumerable
Getting nested content element of Member
Hi All,
I've added a nested content property to a member.
In my UmbracoAPIController when I want to 'fetch' that property, with the following code I get null back.
member.GetValue<IEnumerable<IPublishedElement>>("challenges");
Where
member
is of typeIMember
But when I debug my code and use
member.GetValue("challenges");
i get do get the element back.So it looks like somehow Umbraco isn't able to parse the element. Or maybe I'm doing something wrong, which is the more logical option
Testing with member.HasProperty("challenges") returns true
trying to cast the value
(IEnumerable<IPublishedElement>)cursistMember.GetValue("challenges")
results in an invalid cast exceptionTo make it a little stranger...if I get the Member as IPublishedContent first
and use the methods of IPublishedContent to get the property
It suddenly works!?
Hi Garret,
The reason you are seeing this behaviour is that IMember / IContent behave differently to the "Published" version.
IContent/IMember's .GetValue method is returning the raw json array string and has no understanding of PropertyValueConverters at this point. If you wanted to get the strongly typed version you would need to get the right property value converter and pass the raw string value in to get the right value out.
Does that make sense?
Nik
I had the realisation last night that you need a PropertyValueConverter and that GetValue<> of IContent/IMember probably doesn't have a PropertyValueConverter for NestedContent (or IEnumerable
But I do see a more than one use case for having a NestedContent property for a member (enrolled in certain entities, documents belonging to a member, etc, etc). So would be great if IMember would have the PropertyValueConverter for IEnumerable
is working on a reply...