summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-26 22:29:47 +0200
committerJason Smith <jason.smith@xamarin.com>2016-09-26 13:29:47 -0700
commit55f066584c507ec92d5054fac4f3a35f54c05522 (patch)
tree358ec7ed9a74e008b3bc601a9b391bcd193fb86b /Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
parente6a20ddedb6c8dee989b4ac19c6e83cecafe9f29 (diff)
downloadxamarin-forms-55f066584c507ec92d5054fac4f3a35f54c05522.tar.gz
xamarin-forms-55f066584c507ec92d5054fac4f3a35f54c05522.tar.bz2
xamarin-forms-55f066584c507ec92d5054fac4f3a35f54c05522.zip
[XamlC] Compiled converters (#358)
Diffstat (limited to 'Xamarin.Forms.Build.Tasks/NodeILExtensions.cs')
-rw-r--r--Xamarin.Forms.Build.Tasks/NodeILExtensions.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs b/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
index 084151ba..a7fed895 100644
--- a/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
@@ -51,6 +51,21 @@ namespace Xamarin.Forms.Build.Tasks
var module = context.Body.Method.Module;
var str = (string)node.Value;
+ //If the TypeConverter has a ProvideCompiledAttribute that can be resolved, shortcut this
+ var compiledConverterName = typeConverter?.GetCustomAttribute (module.Import(typeof(ProvideCompiledAttribute)))?.ConstructorArguments?.First().Value as string;
+ Type compiledConverterType;
+ if (compiledConverterName != null && (compiledConverterType = Type.GetType (compiledConverterName)) != null) {
+ var compiledConverter = Activator.CreateInstance (compiledConverterType);
+ var converter = typeof(ICompiledTypeConverter).GetMethods ().FirstOrDefault (md => md.Name == "ConvertFromString");
+ var instructions = (IEnumerable<Instruction>)converter.Invoke (compiledConverter, new object[] {
+ node.Value as string, context.Body.Method.Module, node as BaseNode});
+ foreach (var i in instructions)
+ yield return i;
+ if (targetTypeRef.IsValueType && boxValueTypes)
+ yield return Instruction.Create (OpCodes.Box, module.Import (targetTypeRef));
+ yield break;
+ }
+
//If there's a [TypeConverter], use it
if (typeConverter != null)
{