private DocumentNode FindProjectResource(IProject project, ResourceDictionaryContentProvider currentThemeProvider, string currentThemePath, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            List <string> resolvedUris = new List <string>();

            return(ThemeContentProvider.FindResource(currentThemeProvider, currentThemePath, (Func <ResourceDictionaryContentProvider, Func <DocumentNode, object> >)(provider => (Func <DocumentNode, object>)(resourceKeyNode =>
            {
                DocumentNode rootNode = currentThemeProvider.Document.RootNode;
                using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(rootNode.Context, this.designerContext))
                {
                    using (instanceBuilderContext.DisablePostponedResourceEvaluation())
                    {
                        instanceBuilderContext.ViewNodeManager.RootNodePath = new DocumentNodePath(rootNode, resourceKeyNode);
                        instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root);
                        return instanceBuilderContext.ViewNodeManager.ValidRootInstance;
                    }
                }
            })), (Func <Uri, string, string>)((relativeUri, sourcePath) =>
            {
                Uri uri = project.MakeDesignTimeUri(relativeUri, sourcePath);
                if (!(uri != (Uri)null))
                {
                    return (string)null;
                }
                string originalString = uri.OriginalString;
                if (resolvedUris.Contains(originalString))
                {
                    return (string)null;
                }
                resolvedUris.Add(originalString);
                return originalString;
            }), (Func <string, ResourceDictionaryContentProvider>)(resolvedUri =>
            {
                if (!string.IsNullOrEmpty(resolvedUri))
                {
                    IProjectItem projectItem = project.FindItem(DocumentReference.Create(resolvedUri));
                    if (projectItem != null)
                    {
                        return this.designerContext.ResourceManager.GetContentProviderForResourceDictionary(projectItem);
                    }
                }
                return (ResourceDictionaryContentProvider)null;
            }), resourceKey, out auxillaryResources));
        }
        private DocumentNode GetResourceInternal(Dictionary <ThemeContentProvider.PlatformSpecificDocumentReference, ThemeContentProvider.SystemThemeContentProvider> themeCache, ThemeManager manager, IProjectContext projectContext, DocumentReference theme, IAssembly themeAssembly, string themeAssemblyPath, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            ThemeContentProvider.SystemThemeContentProvider cachedThemeContent = this.GetCachedThemeContent(themeCache, manager, projectContext, theme, themeAssembly, themeAssemblyPath, this.designerContext.TextBufferService);
            DocumentNode  documentNode = (DocumentNode)null;
            List <string> resolvedUris = new List <string>();

            if (cachedThemeContent != null)
            {
                documentNode = ThemeContentProvider.FindResource((ResourceDictionaryContentProvider)cachedThemeContent, themeAssemblyPath, (Func <ResourceDictionaryContentProvider, Func <DocumentNode, object> >)(i => new Func <DocumentNode, object>(((ThemeContentProvider.SystemThemeContentProvider)i).CreateInstance)), (Func <Uri, string, string>)((relativeUri, sourcePath) =>
                {
                    if (themeAssembly != null && relativeUri != (Uri)null)
                    {
                        string str1 = "pack://application:,,,/" + themeAssembly.Name + ";component/";
                        Uri uri1    = new Uri(str1);
                        Uri uri2    = KnownProjectBase.MakeDesignTimeUri(relativeUri, str1, sourcePath, themeAssembly.Name, (IEnumerable <IProject>)null);
                        if (uri2 != (Uri)null && uri2.IsAbsoluteUri)
                        {
                            Uri uri3 = uri1.MakeRelativeUri(uri2);
                            if (uri3 != (Uri)null)
                            {
                                string str2 = uri3.OriginalString.ToLowerInvariant();
                                if (resolvedUris.Contains(str2))
                                {
                                    return((string)null);
                                }
                                resolvedUris.Add(str2);
                                return(str2);
                            }
                        }
                    }
                    return((string)null);
                }), (Func <string, ResourceDictionaryContentProvider>)(resolvedUri =>
                {
                    if (themeAssembly != null && !string.IsNullOrEmpty(resolvedUri))
                    {
                        return((ResourceDictionaryContentProvider)this.GetCachedThemeContent(themeCache, manager, projectContext, DocumentReference.Create(Path.Combine(themeAssembly.Name, resolvedUri)), themeAssembly, resolvedUri, this.designerContext.TextBufferService));
                    }
                    return((ResourceDictionaryContentProvider)null);
                }), resourceKey, out auxillaryResources);
            }
            return(documentNode);
        }
        private static DocumentNode FindResource(ResourceDictionaryContentProvider themeContent, string originalThemePath, Func <ResourceDictionaryContentProvider, Func <DocumentNode, object> > provideInstanceForThemeContent, Func <Uri, string, string> provideResolvedUriForMergedDictionary, Func <string, ResourceDictionaryContentProvider> provideContentForMergedDictionary, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            DocumentNode root = (DocumentNode)null;

            auxillaryResources = (IList <DocumentCompositeNode>)null;
            Func <DocumentNode, object> func = provideInstanceForThemeContent(themeContent);

            foreach (DocumentNode documentNode1 in themeContent.Items)
            {
                DocumentCompositeNode entryNode = documentNode1 as DocumentCompositeNode;
                if (entryNode != null)
                {
                    DocumentNode documentNode2 = ResourceNodeHelper.GetResourceEntryKey(entryNode);
                    if (documentNode2 == null)
                    {
                        DocumentCompositeNode documentCompositeNode = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                        if (documentCompositeNode != null)
                        {
                            if (documentCompositeNode.Type.Metadata.ImplicitDictionaryKeyProperty != null)
                            {
                                documentNode2 = documentCompositeNode.Properties[documentCompositeNode.Type.Metadata.ImplicitDictionaryKeyProperty];
                            }
                            if (documentNode2 == null && documentCompositeNode.TypeResolver.IsCapabilitySet(PlatformCapability.NameSupportedAsKey))
                            {
                                documentNode2 = documentCompositeNode.Properties[(IPropertyId)documentCompositeNode.Type.Metadata.NameProperty];
                            }
                        }
                    }
                    if (documentNode2 != null)
                    {
                        object objB = func(documentNode2);
                        if (object.Equals(resourceKey, objB))
                        {
                            root = entryNode.Properties[DictionaryEntryNode.ValueProperty];
                            break;
                        }
                    }
                }
            }
            if (root == null && originalThemePath != null)
            {
                foreach (DocumentNode documentNode in themeContent.Items)
                {
                    DocumentCompositeNode documentCompositeNode = documentNode as DocumentCompositeNode;
                    if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                    {
                        Uri uriValue = documentCompositeNode.GetUriValue(ResourceDictionaryNode.SourceProperty);
                        if (uriValue != (Uri)null)
                        {
                            string originalThemePath1 = provideResolvedUriForMergedDictionary(uriValue, originalThemePath);
                            if (originalThemePath1 != null)
                            {
                                ResourceDictionaryContentProvider themeContent1 = provideContentForMergedDictionary(originalThemePath1);
                                if (themeContent1 != null)
                                {
                                    root = ThemeContentProvider.FindResource(themeContent1, originalThemePath1, provideInstanceForThemeContent, provideResolvedUriForMergedDictionary, provideContentForMergedDictionary, resourceKey, out auxillaryResources);
                                    if (root != null)
                                    {
                                        return(root);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (root != null)
            {
                auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(root);
            }
            return(root);
        }