diff options
Diffstat (limited to 'Xamarin.Forms.Xaml/XamlCompilationAttribute.cs')
-rw-r--r-- | Xamarin.Forms.Xaml/XamlCompilationAttribute.cs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml/XamlCompilationAttribute.cs b/Xamarin.Forms.Xaml/XamlCompilationAttribute.cs new file mode 100644 index 00000000..76199039 --- /dev/null +++ b/Xamarin.Forms.Xaml/XamlCompilationAttribute.cs @@ -0,0 +1,41 @@ +using System; +using System.Reflection; + +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; } + } + + internal 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; + } + } +}
\ No newline at end of file |