[NUI] Change GetDefaultWindow() to static func (#900)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Xaml / XamlResourceIdAttribute.cs
1 using System;
2 using System.ComponentModel;
3 using System.Reflection;
4
5 namespace Tizen.NUI.Xaml
6 {
7     /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
8     [EditorBrowsable(EditorBrowsableState.Never)]
9     [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
10     public sealed class XamlResourceIdAttribute : Attribute
11     {
12         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
13         [EditorBrowsable(EditorBrowsableState.Never)]
14         public string ResourceId { get; set; }
15
16         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
17         [EditorBrowsable(EditorBrowsableState.Never)]
18         public string Path { get; set; }
19
20         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
21         [EditorBrowsable(EditorBrowsableState.Never)]
22         public Type Type { get; set; }
23
24         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
25         [EditorBrowsable(EditorBrowsableState.Never)]
26         public XamlResourceIdAttribute(string resourceId, string path, Type type)
27         {
28             ResourceId = resourceId;
29             Path = path;
30             Type = type;
31         }
32
33         internal static string GetResourceIdForType(Type type)
34         {
35             var assembly = type.GetTypeInfo().Assembly;
36             foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
37                 if (xria.Type == type)
38                     return xria.ResourceId;
39             }
40             return null;
41         }
42
43         internal static string GetPathForType(Type type)
44         {
45             var assembly = type.GetTypeInfo().Assembly;
46             foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
47                 if (xria.Type == type)
48                     return xria.Path;
49             }
50             return null;
51         }
52
53         internal static string GetResourceIdForPath(Assembly assembly, string path)
54         {
55             foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
56                 if (xria.Path == path)
57                     return xria.ResourceId;
58             }
59             return null;
60         }
61
62         internal static Type GetTypeForResourceId(Assembly assembly, string resourceId)
63         {
64             foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
65                 if (xria.ResourceId == resourceId)
66                     return xria.Type;
67             }
68             return null;
69         }
70
71         internal static Type GetTypeForPath(Assembly assembly, string path)
72         {
73             foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
74                 if (xria.Path == path)
75                     return xria.Type;
76             }
77             return null;
78         }
79     }
80 }