[EXaml] Support import xaml to ResourceDictionary in EXaml
authorFang Xiaohui <xiaohui.fang@samsung.com>
Wed, 9 Nov 2022 05:31:27 +0000 (13:31 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 15 Nov 2022 08:27:31 +0000 (17:27 +0900)
pkg/Tizen.NET.API10/xamlbuild/Tizen.NUI.XamlBuild.dll
src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXaml/EXamlCreateObject/EXamlCreateArrayObject.cs
src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXamlSetPropertiesVisitor.cs

index b855cff..24c8525 100644 (file)
Binary files a/pkg/Tizen.NET.API10/xamlbuild/Tizen.NUI.XamlBuild.dll and b/pkg/Tizen.NET.API10/xamlbuild/Tizen.NUI.XamlBuild.dll differ
index 0cdc353..7bb4b1b 100755 (executable)
@@ -37,7 +37,7 @@ namespace Tizen.NUI.EXaml
             }
 
             string itemsString = "";
-            if (0 < items.Count)
+            if (null != items && 0 < items.Count)
             {
                 itemsString += "(";
 
index be707b6..acbabc0 100755 (executable)
@@ -913,6 +913,8 @@ namespace Tizen.NUI.EXaml.Build.Tasks
             var valueNode = node as ValueNode;
             var elementNode = node as IElementNode;
 
+            bool needToSetProperty = true;
+
             //if it's a value type, load the address so we can invoke methods on it
             if (parent.Type.IsValueType)
             {
@@ -937,15 +939,24 @@ namespace Tizen.NUI.EXaml.Build.Tasks
                 }
                 else
                 {
-                    var converterType = valueNode.GetConverterType(new ICustomAttributeProvider[] { property, propertyType.ResolveCached() });
-                    if (null != converterType)
+                    if ("Tizen.NUI.Binding.ResourceDictionary" == parent.GetType().FullName &&
+                        "Source" == property.Name)
                     {
-                        var converterValue = new EXamlValueConverterFromString(context, converterType.Resolve(), valueNode.Value as string);
-                        context.Values[node] = new EXamlCreateObject(context, converterValue, propertyType);
+                        ImportXamlToResourceDictionary(parent, valueNode, context);
+                        needToSetProperty = false;
                     }
                     else
                     {
-                        context.Values[node] = valueNode.GetBaseValue(context, property.PropertyType);
+                        var converterType = valueNode.GetConverterType(new ICustomAttributeProvider[] { property, propertyType.ResolveCached() });
+                        if (null != converterType)
+                        {
+                            var converterValue = new EXamlValueConverterFromString(context, converterType.Resolve(), valueNode.Value as string);
+                            context.Values[node] = new EXamlCreateObject(context, converterValue, propertyType);
+                        }
+                        else
+                        {
+                            context.Values[node] = valueNode.GetBaseValue(context, propertyType);
+                        }
                     }
                 }
             }
@@ -977,7 +988,63 @@ namespace Tizen.NUI.EXaml.Build.Tasks
                 }
             }
 
-            new EXamlSetProperty(context, parent, localName, context.Values[node]);
+            if (needToSetProperty)
+            {
+                new EXamlSetProperty(context, parent, localName, context.Values[node]);
+            }
+        }
+
+        static void ImportXamlToResourceDictionary(EXamlCreateObject parentObj, ValueNode valueNode, EXamlContext context)
+        {
+            var resourceName = valueNode.Value as string;
+
+            foreach (var resource in context.Module.Resources.OfType<EmbeddedResource>())
+            {
+                var embeddedResourceNameSpace = context.EmbeddedResourceNameSpace;
+                if (resource.Name.StartsWith(embeddedResourceNameSpace) && resource.Name.EndsWith(resourceName))
+                {
+                    string classname = null;
+
+                    if (resource.IsResourceDictionaryXaml(context.Module, out classname))
+                    {
+                        int lastIndex = classname.LastIndexOf('.');
+                        var realClassName = classname.Substring(lastIndex + 1);
+                        var typeref = XmlTypeExtensions.GetTypeReference(realClassName, context.Module, valueNode, XmlTypeExtensions.ModeOfGetType.Both);
+
+                        var rootnode = XamlTask.ParseXaml(resource.GetResourceStream(), typeref);
+
+                        var typeDef = typeref.ResolveCached();
+                        var visitorContext = new EXamlContext(typeDef, typeDef.Module, embeddedResourceNameSpace);
+
+                        visitorContext.Values[rootnode] = new EXamlCreateObject(visitorContext, null, rootnode.TypeReference);
+
+                        rootnode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null);
+                        rootnode.Accept(new EXamlExpandMarkupsVisitor(visitorContext), null);
+                        rootnode.Accept(new PruneIgnoredNodesVisitor(), null);
+                        rootnode.Accept(new EXamlCreateObjectVisitor(visitorContext), null);
+                        rootnode.Accept(new EXamlSetNamescopesAndRegisterNamesVisitor(visitorContext), null);
+                        rootnode.Accept(new EXamlSetFieldVisitor(visitorContext), null);
+                        rootnode.Accept(new EXamlSetResourcesVisitor(visitorContext), null);
+                        rootnode.Accept(new EXamlSetPropertiesVisitor(visitorContext, true), null);
+
+                        foreach (var pair in visitorContext.resourceDictionary)
+                        {
+                            new EXamlAddToResourceDictionary(context, parentObj, pair.Key, pair.Value);
+                        }
+
+                        break;
+                    }
+                }
+            }
+
+            //rootnode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null);
+            //rootnode.Accept(new EXamlExpandMarkupsVisitor(context), null);
+            //rootnode.Accept(new PruneIgnoredNodesVisitor(), null);
+            //rootnode.Accept(new EXamlCreateObjectVisitor(context), null);
+            //rootnode.Accept(new EXamlSetNamescopesAndRegisterNamesVisitor(context), null);
+            //rootnode.Accept(new EXamlSetFieldVisitor(context), null);
+            //rootnode.Accept(new EXamlSetResourcesVisitor(context), null);
+            //rootnode.Accept(new EXamlSetPropertiesVisitor(context, true), null);
         }
 
         static void Get(EXamlCreateObject parent, string localName, IXmlLineInfo iXmlLineInfo, EXamlContext context, out TypeReference propertyType)