[Xaml] Support import other xaml as the source of resource dictionary
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.XamlBuild / src / public / XamlBuild / XamlCTask.cs
index 8827aff..32ae825 100755 (executable)
@@ -380,6 +380,17 @@ namespace Tizen.NUI.Xaml.Build.Tasks
             return success;
         }
 
+        private string GetNameSpaceOfResource(EmbeddedResource resource)
+        {
+            var index = resource.Name.LastIndexOf('.');
+            var resourceNameWithoutSubfix = resource.Name.Substring(0, index);
+
+            index = resourceNameWithoutSubfix.LastIndexOf('.');
+            var nameSpace = resourceNameWithoutSubfix.Substring(0, index);
+
+            return nameSpace;
+        }
+
         bool DoInjection(TypeDefinition typeDef, EmbeddedResource resource, out IList<Exception> thrownExceptions)
         {
             thrownExceptions = null;
@@ -431,7 +442,9 @@ namespace Tizen.NUI.Xaml.Build.Tasks
 
             LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
             Exception e;
-            if (!TryCoreCompile(initComp, rootnode, out e))
+
+            var embeddedResourceNameSpace = GetNameSpaceOfResource(resource);
+            if (!TryCoreCompile(initComp, rootnode, embeddedResourceNameSpace, out e))
             {
                 LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
                 (thrownExceptions = thrownExceptions ?? new List<Exception>()).Add(e);
@@ -494,7 +507,8 @@ namespace Tizen.NUI.Xaml.Build.Tasks
             LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
             Exception e;
 
-            var visitorContext = new EXamlContext(typeDef, typeDef.Module);
+            var embeddedResourceNameSpace = GetNameSpaceOfResource(resource);
+            var visitorContext = new EXamlContext(typeDef, typeDef.Module, embeddedResourceNameSpace);
 
             if (!TryCoreCompile(rootnode, visitorContext, out e))
             {
@@ -567,7 +581,7 @@ namespace Tizen.NUI.Xaml.Build.Tasks
             LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
             Exception e;
 
-            var visitorContext = new EXamlContext(typeDef, module);
+            var visitorContext = new EXamlContext(typeDef, module, null);
 
             if (!TryCoreCompile(rootnode, visitorContext, out e))
             {
@@ -621,7 +635,7 @@ namespace Tizen.NUI.Xaml.Build.Tasks
             return true;
         }
 
-        bool TryCoreCompile(MethodDefinition initComp, ILRootNode rootnode, out Exception exception)
+        bool TryCoreCompile(MethodDefinition initComp, ILRootNode rootnode, string embeddedResourceNameSpace, out Exception exception)
         {
             try
             {
@@ -646,7 +660,7 @@ namespace Tizen.NUI.Xaml.Build.Tasks
 
                 List<Instruction> insOfAddEvent = new List<Instruction>();
 
-                var visitorContext = new ILContext(il, body, insOfAddEvent, module);
+                var visitorContext = new ILContext(il, body, insOfAddEvent, module, embeddedResourceNameSpace);
 
                 rootnode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null);
                 rootnode.Accept(new ExpandMarkupsVisitor(visitorContext), null);