2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Reflection;
22 using Tizen.NUI.Binding.Internals;
24 // [assembly:Dependency(typeof(Tizen.NUI.Xaml.ResourcesLoader))]
25 namespace Tizen.NUI.Xaml
27 internal class ResourcesLoader : IResourcesLoader
29 public T CreateFromResource<T>(string resourcePath, Assembly assembly, IXmlLineInfo lineInfo) where T : new()
32 var resourceLoadingResponse = ResourceLoader.ResourceProvider?.Invoke(new ResourceLoader.ResourceLoadingQuery
34 AssemblyName = assembly.GetName(),
35 ResourcePath = resourcePath,
38 var alternateResource = resourceLoadingResponse?.ResourceContent;
39 if (alternateResource != null)
41 rd.LoadFromXaml(alternateResource);
45 var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(assembly, resourcePath);
46 if (resourceId == null)
47 throw new XamlParseException($"Resource '{resourcePath}' not found.", lineInfo);
49 using (var stream = assembly.GetManifestResourceStream(resourceId))
52 throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
53 using (var reader = new StreamReader(stream))
55 rd.LoadFromXaml(reader.ReadToEnd());
61 public string GetResource(string resourcePath, Assembly assembly, object target, IXmlLineInfo lineInfo)
63 var resourceLoadingResponse = ResourceLoader.ResourceProvider?.Invoke(new ResourceLoader.ResourceLoadingQuery {
64 AssemblyName = assembly.GetName(),
65 ResourcePath = resourcePath,
68 var alternateResource = resourceLoadingResponse?.ResourceContent;
69 if (alternateResource != null)
70 return alternateResource;
72 var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(assembly, resourcePath);
73 if (resourceId == null)
74 throw new XamlParseException($"Resource '{resourcePath}' not found.", lineInfo);
76 using (var stream = assembly.GetManifestResourceStream(resourceId))
79 throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
80 using (var reader = new StreamReader(stream))
81 return reader.ReadToEnd();