Skip to content

Instantly share code, notes, and snippets.

@janvanderhaegen
Created January 22, 2014 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janvanderhaegen/8559519 to your computer and use it in GitHub Desktop.
Save janvanderhaegen/8559519 to your computer and use it in GitHub Desktop.
Finds contentitems for an IEntityProperty
public static List<IContentItem> FindContentItems(this IScreenObject screen, IEntityProperty viewModel)
{
IPresentationScreenView screenView = VsExportProviderService
.GetServiceFromCache<IServiceProxy>().ScreenViewService.GetScreenView(screen) as IPresentationScreenView;
if (screenView == null)
{
throw new InvalidOperationException();
}
IContentItem currentView = screenView.ContentItemTree;
var alreadyFoundViews = new List<IContentItem>();
FindContentItems(currentView, viewModel, alreadyFoundViews);
return alreadyFoundViews;
}
private static void FindContentItems(IContentItem currentView, IEntityProperty viewModel, List<IContentItem> alreadyFoundViews)
{
if (currentView != null)
{
if (currentView.Details != null && currentView.Details.Equals(viewModel))
{
alreadyFoundViews.Add(currentView);
}
foreach (var child in currentView.ChildItems)
{
FindContentItems(child, viewModel, alreadyFoundViews);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment