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