[NUI] Support the different file name of Xaml (#1816)
authorAdunFang <30402408+AdunFang@users.noreply.github.com>
Wed, 15 Jul 2020 04:50:30 +0000 (12:50 +0800)
committerGitHub <noreply@github.com>
Wed, 15 Jul 2020 04:50:30 +0000 (13:50 +0900)
Co-authored-by: Fang Xiaohui <xiaohui fang>
src/Tizen.NUI/src/internal/Xaml/XamlLoader.cs
src/Tizen.NUI/src/internal/XamlBinding/ResourcesExtensions.cs
src/Tizen.NUI/src/public/XamlBinding/ContentPage.cs

index 317dce2..99056ad 100755 (executable)
@@ -272,39 +272,29 @@ namespace Tizen.NUI.Xaml
             {
                 Assembly assembly = type.Assembly;
 
-                Stream stream = null;
-
-                foreach (string str in assembly.GetManifestResourceNames())
-                {
-                    string resourceClassName = str.Substring(0, str.LastIndexOf('.'));
-                    int index = resourceClassName.LastIndexOf('.');
-                    if (0 <= index && index < resourceClassName.Length)
-                    {
-                        resourceClassName = resourceClassName.Substring(index + 1);
-
-                        if (resourceClassName == type.Name)
-                        {
-                            stream = assembly.GetManifestResourceStream(str);
-                            break;
-                        }
-                    }
-                }
-
-                if (null == stream)
+                var resourceId = XamlResourceIdAttribute.GetResourceIdForType(type);
+                if (null == resourceId)
                 {
                     throw new XamlParseException(string.Format("Can't find type {0} in embedded resource", type.FullName), new XmlLineInfo());
                 }
                 else
                 {
-                    Byte[] buffer = new byte[stream.Length];
-                    stream.Read(buffer, 0, (int)stream.Length);
+                    Stream stream = assembly.GetManifestResourceStream(resourceId);
 
-                    string ret = System.Text.Encoding.Default.GetString(buffer);
-                    return ret;
+                    if (null != stream)
+                    {
+                        Byte[] buffer = new byte[stream.Length];
+                        stream.Read(buffer, 0, (int)stream.Length);
+
+                        string ret = System.Text.Encoding.Default.GetString(buffer);
+                        return ret;
+                    }
+                    else
+                    {
+                        throw new XamlParseException(string.Format("Can't get xaml stream {0} in embedded resource", type.FullName), new XmlLineInfo());
+                    }
                 }
             }
-
-            return null;
         }
 
         //if the assembly was generated using a version of XamlG that doesn't outputs XamlResourceIdAttributes, we still need to find the resource, and load it
index a598985..4c0f37d 100755 (executable)
@@ -14,6 +14,11 @@ namespace Tizen.NUI.Binding
                 if (ve != null && ve.IsResourcesCreated)
                 {
                     resources = resources ?? new Dictionary<string, object>();
+                    if (null == resources)
+                    {
+                        return null;
+                    }
+
                     if (ve.XamlResources != null)
                     {
                         foreach (KeyValuePair<string, object> res in ve.XamlResources.MergedResources)
@@ -27,10 +32,16 @@ namespace Tizen.NUI.Binding
                             }
                     }
                 }
+
                 var app = element as Application;
                 if (app != null && app.SystemResources != null)
                 {
                     resources = resources ?? new Dictionary<string, object>(8);
+                    if (null == resources)
+                    {
+                        return null;
+                    }
+
                     foreach (KeyValuePair<string, object> res in app.SystemResources)
                         if (!resources.ContainsKey(res.Key))
                             resources.Add(res.Key, res.Value);
index 7437e80..60113ae 100755 (executable)
@@ -260,7 +260,7 @@ namespace Tizen.NUI
                 }
                 if (trans)
                 {
-                    transDictionary.Add(trans.Name, trans);
+                    transDictionary?.Add(trans.Name, trans);
                 }
             }
         }