volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Compare Blocks to BlockProxies

The EpiServer internally uses a lot of proxies for Blocks and Pages.

In the ContentArea I placed MyBlock. I would like to get blocks from code. I filter them like:

currentPage.MyContentArea.FilteredContents.OfType<MyBlock>()

but I always get empty list cause currentPage.MyContentArea.FilteredContents is collection of {Castle.Proxies.MyBlockProxy}

How to solve it?

#74656
Sep 03, 2013 15:07

I have just found one possibility to deal with it:

 

var list = new List<MyBlock>();

foreach (var filteredContent in filteredContents)
{
var myBlock = filteredContent as MyBlock;
if (myBlock != null)
{
list.Add(myBlock);
}
}

#74657
Sep 03, 2013 15:17
Vote:

Can you make use of .Cast<T>() ?

#74658
Sep 03, 2013 15:37

Simple and powerful! Thanks

#74659
Sep 03, 2013 15:42
error This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.