[NUI] remove "_" and refactoring naming to pascal case.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Xaml / ResourcesLoader.cs
1 using System;
2 using System.IO;
3 using System.Reflection;
4 using Tizen.NUI;
5 using System.Xml;
6 using Tizen.NUI.Binding.Internals;
7
8 // [assembly:Dependency(typeof(Tizen.NUI.Xaml.ResourcesLoader))]
9 namespace Tizen.NUI.Xaml
10 {
11     internal class ResourcesLoader : IResourcesLoader
12     {
13         public T CreateFromResource<T>(string resourcePath, Assembly assembly, IXmlLineInfo lineInfo) where T : new()
14         {
15             var alternateResource = ResourceLoader.ResourceProvider?.Invoke(assembly.GetName(), resourcePath);
16             if (alternateResource != null)
17             {
18                 var rd = new T();
19                 rd.LoadFromXaml(alternateResource);
20                 return rd;
21             }
22
23             var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(assembly, resourcePath);
24             if (resourceId == null)
25                 throw new XamlParseException($"Resource '{resourcePath}' not found.", lineInfo);
26
27             using (var stream = assembly.GetManifestResourceStream(resourceId))
28             {
29                 if (stream == null)
30                     throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
31                 using (var reader = new StreamReader(stream))
32                 {
33                     var rd = new T();
34                     rd.LoadFromXaml(reader.ReadToEnd());
35                     return rd;
36                 }
37             }
38         }
39
40         public string GetResource(string resourcePath, Assembly assembly, IXmlLineInfo lineInfo)
41         {
42             var alternateResource = ResourceLoader.ResourceProvider?.Invoke(assembly.GetName(), resourcePath);
43             if (alternateResource != null)
44                 return alternateResource;
45
46             var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(assembly, resourcePath);
47             if (resourceId == null)
48                 throw new XamlParseException($"Resource '{resourcePath}' not found.", lineInfo);
49
50             using (var stream = assembly.GetManifestResourceStream(resourceId))
51             {
52                 if (stream == null)
53                     throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
54                 using (var reader = new StreamReader(stream))
55                     return reader.ReadToEnd();
56             }
57         }
58     }
59 }