[NUI] Change GetDefaultWindow() to static func (#900)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Xaml / XamlCompilationAttribute.cs
1 using System;
2 using System.Reflection;
3 using System.Runtime.CompilerServices;
4
5 namespace Tizen.NUI.Xaml
6 {
7     [Flags]
8     internal enum XamlCompilationOptions
9     {
10         Skip = 1 << 0,
11         Compile = 1 << 1
12     }
13
14     [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class, Inherited = false)]
15     internal sealed class XamlCompilationAttribute : Attribute
16     {
17         public XamlCompilationAttribute(XamlCompilationOptions xamlCompilationOptions)
18         {
19             XamlCompilationOptions = xamlCompilationOptions;
20         }
21
22         public XamlCompilationOptions XamlCompilationOptions { get; set; }
23     }
24
25     internal static class XamlCExtensions
26     {
27         public static bool IsCompiled(this Type type)
28         {
29             var attr = type.GetTypeInfo().GetCustomAttribute<XamlCompilationAttribute>();
30             if (attr != null)
31                 return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
32             attr = type.GetTypeInfo().Module.GetCustomAttribute<XamlCompilationAttribute>();
33             if (attr != null)
34                 return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
35             attr = type.GetTypeInfo().Assembly.GetCustomAttribute<XamlCompilationAttribute>();
36             if (attr != null)
37                 return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
38
39             return false;
40         }
41     }
42 }