Example #1
0
        private void BuildAmbientResources(XamlFileDefinition[] files, XamlGlobalStaticResourcesMap map)
        {
            // Lookup for GlobalStaticResources classes in external assembly
            // references only, and in Uno.UI itself for generic.xaml-like resources.

            var query = from ext in _metadataHelper.Compilation.ExternalReferences
                        let sym = _metadataHelper.Compilation.GetAssemblyOrModuleSymbol(ext) as IAssemblySymbol
                                  where sym != null
                                  from module in sym.Modules
                                  from reference in module.ReferencedAssemblies
                                  where reference.Name == "Uno.UI" || sym.Name == "Uno.UI"
                                  from typeName in sym.GlobalNamespace.GetNamespaceTypes()
                                  where typeName.Name.EndsWith("GlobalStaticResources")
                                  select typeName;

            _ambientGlobalResources = query.Distinct().ToArray();

            foreach (var ambientResources in _ambientGlobalResources)
            {
                var publicProperties = from member in ambientResources.GetAllProperties()
                                       where member.DeclaredAccessibility == Microsoft.CodeAnalysis.Accessibility.Public
                                       select member;


                foreach (var member in publicProperties)
                {
                    map.Add(member.Name, ambientResources.ContainingNamespace.ToDisplayString(), XamlGlobalStaticResourcesMap.ResourcePrecedence.System);
                }
            }
        }
Example #2
0
        private void BuildLocalProjectResources(XamlFileDefinition[] files, XamlGlobalStaticResourcesMap map)
        {
            foreach (var file in files)
            {
                var topLevelControl = file.Objects.FirstOrDefault();

                if (topLevelControl?.Type.Name == "ResourceDictionary")
                {
                    BuildResourceMap(topLevelControl, map);

                    var themeDictionaries = topLevelControl.Members.FirstOrDefault(m => m.Member.Name == "ThemeDictionaries");

                    if (themeDictionaries != null)
                    {
                        // We extract all distinct keys of all themed resource dictionaries defined and add them to global map

                        IEnumerable <string> GetResources(XamlObjectDefinition themeDictionary)
                        {
                            if (!(themeDictionary.Members
                                  .FirstOrDefault(x => x.Member.Name.Equals("Key"))
                                  ?.Value is string))
                            {
                                yield break;
                            }

                            var resources = themeDictionary.Members
                                            .FirstOrDefault(x => x.Member.Name.Equals("_UnknownContent"))
                                            ?.Objects;

                            if (resources != null)
                            {
                                foreach (var resource in resources)
                                {
                                    if (resource.Members.FirstOrDefault(x => x.Member.Name.Equals("Key"))
                                        ?.Value is string resourceKey)
                                    {
                                        yield return(resourceKey);
                                    }
                                }
                            }
                        }

                        var themeResources = themeDictionaries
                                             .Objects
                                             .SelectMany(GetResources)
                                             .Distinct();

                        foreach (var themeResource in themeResources)
                        {
                            map.Add(themeResource, _defaultNamespace, XamlGlobalStaticResourcesMap.ResourcePrecedence.Local);
                        }
                    }
                }
            }
        }
Example #3
0
        private void BuildResourceMap(XamlObjectDefinition parentNode, XamlGlobalStaticResourcesMap map)
        {
            var contentNode = parentNode.Members.FirstOrDefault(m => m.Member.Name == "_UnknownContent");

            if (contentNode != null)
            {
                foreach (var resource in contentNode.Objects)
                {
                    var key = resource.Members.FirstOrDefault(m => m.Member.Name == "Key");

                    if (key != null)
                    {
                        map.Add(key.Value.ToString(), _defaultNamespace, XamlGlobalStaticResourcesMap.ResourcePrecedence.Local);
                    }
                }
            }
        }