I get an error if member.GetValue(variable) doesn't exist however, so I'm trying to test for that, by saying if member.GetValue(variable) is null then set "value" to something static. Unfortunately as soon as member.GetValue(variable) is reached it just throws a "given key was not present in the dictionary" error if it doesn't exist.
Testing if current Member has a Property
I'm currently getting Member values like so:
variable = "PropertyName";
value = member.GetValue(variable).ToString();
I get an error if member.GetValue(variable) doesn't exist however, so I'm trying to test for that, by saying if member.GetValue(variable) is null then set "value" to something static. Unfortunately as soon as member.GetValue(variable) is reached it just throws a "given key was not present in the dictionary" error if it doesn't exist.
Any idea how I can test for this?
Many thanks.
Hey Robzor,
You could try the following bit of code:
Or possibly turn it into an Extension Method for uses with other property aliases.
I hope this helps.
Thanks,
Jamie
Or, if your member is of type
IPublishedContent
(I don't know which member API you're using) then it's as simple as:member.HasValue(variable)
.Hi Jamie,
This worked perfectly, thanks a lot!
is working on a reply...