You indeed do not need reflection, you can enumerate all properties of IPublishedContent with their own API. So your method could probably be written like this (untested code though):
public static bool HasDealerLocatorContentBlock(this IPublishedContent content)
{
if(content is null)
{
return false;
}
foreach (var property in content.Properties)
{
if (property.PropertyType.EditorAlias == Perplex.ContentBlocks.Constants.PropertyEditor.Alias &&
content.Value<IContentBlocks>(property.Alias) is IContentBlocks contentBlocks &&
contentBlocks.Blocks.Any(b => b.Content is DealerLocatorBlock))
{
return true;
}
}
return false;
}
Perplex ContentBlocks: Determine in masterpage what kind of content blocks are used
Hi Daniël,
On the masterpage we want to determine what type of content blocks are used for the loaded page.
Now I have this extension method, but I think it can be done without reflection.
Hi Peter,
You indeed do not need reflection, you can enumerate all properties of
IPublishedContent
with their own API. So your method could probably be written like this (untested code though):Thanks Daniël!
is working on a reply...