Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / XamlBinding / Internals / ResourceLoader.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using System.IO;
19 using System.Reflection;
20 using Tizen.NUI.Xaml;
21
22 namespace Tizen.NUI.Binding.Internals
23 {
24     internal static class ResourceLoader
25     {
26         static Func<ResourceLoadingQuery, ResourceLoadingResponse> _resourceProvider = (resourceLoadingQuery) => {
27             if (typeof(Theme).Assembly.GetName().FullName != resourceLoadingQuery.AssemblyName.FullName)
28             {
29                 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
30                 resourceLoadingQuery.ResourcePath = resource + resourceLoadingQuery.ResourcePath;
31             }
32
33             string ret = File.ReadAllText(resourceLoadingQuery.ResourcePath);
34             return new ResourceLoadingResponse { ResourceContent = ret };
35         };
36         public static Func<ResourceLoadingQuery, ResourceLoadingResponse> ResourceProvider
37         {
38             get => _resourceProvider;
39             internal set
40             {
41                 DesignMode.IsDesignModeEnabled = value != null;
42                 _resourceProvider = value;
43             }
44         }
45
46         internal static Action<(Exception exception, string filepath)> ExceptionHandler { get; set; }
47
48         public class ResourceLoadingQuery
49         {
50             public AssemblyName AssemblyName { get; set; }
51             public string ResourcePath { get; set; }
52             public object Instance { get; set; }
53         }
54
55         public class ResourceLoadingResponse
56         {
57             public string ResourceContent { get; set; }
58             public bool UseDesignProperties { get; set; }
59         }
60     }
61 }