diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-09-26 22:29:47 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-09-26 13:29:47 -0700 |
commit | 55f066584c507ec92d5054fac4f3a35f54c05522 (patch) | |
tree | 358ec7ed9a74e008b3bc601a9b391bcd193fb86b /Xamarin.Forms.Build.Tasks/NodeILExtensions.cs | |
parent | e6a20ddedb6c8dee989b4ac19c6e83cecafe9f29 (diff) | |
download | xamarin-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.cs | 15 |
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) { |