summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-12 21:02:37 (GMT)
committerGitHub <noreply@github.com>2016-12-12 21:02:37 (GMT)
commit6112526432a61816b2558a4b9ba10327c3c2244f (patch)
treecad98732e29969742e36f008c9d316300c3530bc /Xamarin.Forms.Build.Tasks
parent354e27c09603143cef43d666be5beaed8928c040 (diff)
downloadxamarin-forms-6112526432a61816b2558a4b9ba10327c3c2244f.zip
xamarin-forms-6112526432a61816b2558a4b9ba10327c3c2244f.tar.gz
xamarin-forms-6112526432a61816b2558a4b9ba10327c3c2244f.tar.bz2
[XamlC] Compile TypeTypeConverter (#615)
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs3
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs44
-rw-r--r--Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj1
3 files changed, 46 insertions, 2 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs
index af48066..a7eda95 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs
@@ -1,5 +1,4 @@
-´╗┐using System;
-using System.Collections.Generic;
+´╗┐using System.Collections.Generic;
using System.Globalization;
using System.Linq;
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs
new file mode 100644
index 0000000..93c3ee5
--- /dev/null
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Xml;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+using Xamarin.Forms.Build.Tasks;
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Core.XamlC
+{
+ class TypeTypeConverter : ICompiledTypeConverter
+ {
+ public IEnumerable<Instruction> ConvertFromString(string value, ModuleDefinition module, BaseNode node)
+ {
+ if (string.IsNullOrEmpty(value))
+ goto error;
+
+ var split = value.Split(':');
+ if (split.Length > 2)
+ goto error;
+
+ XmlType xmlType;
+ if (split.Length == 2)
+ xmlType = new XmlType(node.NamespaceResolver.LookupNamespace(split[0]), split[1], null);
+ else
+ xmlType = new XmlType(node.NamespaceResolver.LookupNamespace(""), split[0], null);
+
+ var typeRef = xmlType.GetTypeReference(module, (IXmlLineInfo)node);
+ if (typeRef == null)
+ goto error;
+
+ var getTypeFromHandle = module.Import(typeof(Type).GetMethod("GetTypeFromHandle", new[] { typeof(RuntimeTypeHandle) }));
+ yield return Instruction.Create(OpCodes.Ldtoken, module.Import(typeRef));
+ yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
+ yield break;
+
+ error:
+ throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(Type)}", node);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
index 589d006..ef10720 100644
--- a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
+++ b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
@@ -104,6 +104,7 @@
<Compile Include="CompiledConverters\ConstraintTypeConverter.cs" />
<Compile Include="CompiledConverters\ThicknessTypeConverter.cs" />
<Compile Include="MethodBodyExtensions.cs" />
+ <Compile Include="CompiledConverters\TypeTypeConverter.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">