summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/MockCompiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests/MockCompiler.cs')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/MockCompiler.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/MockCompiler.cs b/Xamarin.Forms.Xaml.UnitTests/MockCompiler.cs
new file mode 100644
index 00000000..404169b3
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/MockCompiler.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using Xamarin.Forms.Build.Tasks;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public static class MockCompiler
+ {
+ public static void Compile(Type type)
+ {
+ var assembly = type.Assembly.Location;
+ var refs = from an in type.Assembly.GetReferencedAssemblies()
+ let a = System.Reflection.Assembly.Load(an)
+ select a.Location;
+
+ var xamlc = new XamlCTask {
+ Assembly = assembly,
+ ReferencePath = string.Join(";", refs),
+ KeepXamlResources = true,
+ Type = type.FullName
+ };
+
+ var exceptions = new List<Exception>();
+ if (!xamlc.Compile(exceptions) && exceptions.Any())
+ throw exceptions [0];
+ }
+ }
+} \ No newline at end of file