Straight to the point, was is the advantage of using HasValue("something") vs strongly typed? Is it cache related, or just a simpler way of checking values?
string awesomevar = Model.Content.GetPropertyValue<string>("somestring");
// This
if ( !awesomevar.IsNullOrWhiteSpace() ) {}
// VS this
if ( Model.Content.HasValue("somestring") ) {}
They should be pretty much equivalent for string values. HasValue does a simpler test, so it may be slightly quicker if you're filtering a large list of content.
For other strongly-typed values, reading the value may be a stronger test. HasValue always just tests whether there's a non-empty, non-whitespace value for that property in the XML cache. GetPropertyValue<T> also checks that it can convert that value to the type you asked for. Perhaps you've got a content picker which refers to an item which has been deleted. HasValue will just see the ID and return true, but GetPropertyValue<IPublishedContent> would return null.
HasValue vs Strongly Typed
Straight to the point, was is the advantage of using
HasValue("something")
vs strongly typed? Is it cache related, or just a simpler way of checking values?They should be pretty much equivalent for string values.
HasValue
does a simpler test, so it may be slightly quicker if you're filtering a large list of content.For other strongly-typed values, reading the value may be a stronger test.
HasValue
always just tests whether there's a non-empty, non-whitespace value for that property in the XML cache.GetPropertyValue<T>
also checks that it can convert that value to the type you asked for. Perhaps you've got a content picker which refers to an item which has been deleted.HasValue
will just see the ID and returntrue
, butGetPropertyValue<IPublishedContent>
would return null.So the strongly typed / native way of null checks and so on, would be preferable for more correct results?
And in theory
HasValue
should be faster after the content has been cached? But can give incorrect results in case of cache issue?is working on a reply...