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