summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-05 12:40:12 (GMT)
committerGitHub <noreply@github.com>2016-12-05 12:40:12 (GMT)
commitf9a44ed5ba4db08d0855570a9ed6a618b6b80c56 (patch)
treed8a496ccfaf7682bba1bfb25d5024b0ec1a364a2 /Xamarin.Forms.Build.Tasks
parent1a5bead2f2e24cc16da23753eaf0882d38d54ea1 (diff)
downloadxamarin-forms-f9a44ed5ba4db08d0855570a9ed6a618b6b80c56.zip
xamarin-forms-f9a44ed5ba4db08d0855570a9ed6a618b6b80c56.tar.gz
xamarin-forms-f9a44ed5ba4db08d0855570a9ed6a618b6b80c56.tar.bz2
[XamlC] Compile ContraintTypeConverters (#592)
* [XamlC] Compile ContraintTypeConverters * fix error message
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs28
-rw-r--r--Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj1
2 files changed, 29 insertions, 0 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs
new file mode 100644
index 0000000..18b1810
--- /dev/null
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs
@@ -0,0 +1,28 @@
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Core.XamlC
+{
+ class ConstraintTypeConverter : ICompiledTypeConverter
+ {
+ public IEnumerable<Instruction> ConvertFromString(string value, ModuleDefinition module, BaseNode node)
+ {
+ double size;
+
+ if (string.IsNullOrEmpty(value) || !double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out size))
+ throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(Constraint)}", node);
+
+ yield return Instruction.Create(OpCodes.Ldc_R8, size);
+
+ var constantDef = module.Import(typeof(Constraint)).Resolve().Methods.FirstOrDefault(md => md.IsStatic && md.Name == "Constant");
+ var constantRef = module.Import(constantDef);
+ yield return Instruction.Create(OpCodes.Call, constantRef);
+ }
+ }
+}
diff --git a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
index c845b59..9507ea3 100644
--- a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
+++ b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
@@ -101,6 +101,7 @@
<Compile Include="Logger.cs" />
<Compile Include="XamlTask.cs" />
<Compile Include="CompiledMarkupExtensions\ArrayExtension.cs" />
+ <Compile Include="CompiledConverters\ConstraintTypeConverter.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">