4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Globalization;
8 using System.Reflection;
11 using Tizen.NUI.Xaml.Build.Tasks;
13 namespace Tizen.NUI.Xaml.Core.XamlC
15 internal class ExtentsTypeConverter : ICompiledTypeConverter
17 IEnumerable<Instruction> GenerateIL(ModuleDefinition module, params ushort[] args)
19 foreach (var d in args)
20 yield return Instruction.Create(OpCodes.Ldc_I4, d);
22 yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference((XamlTask.nuiAssemblyName, XamlTask.nuiNameSpace, "Extents"),
23 parameterTypes: args.Select(a => ("mscorlib", "System", "UInt16")).ToArray()));
26 public IEnumerable<Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
28 var module = context.Body.Method.Module;
30 if (!string.IsNullOrEmpty(value))
32 var thickness = value.Split(',');
34 foreach (var thick in thickness)
36 if (thick.EndsWith("dp") || thick.EndsWith("px"))
42 if (4 == thickness.Length)
44 ushort start, end, top, bottom;
46 if (ushort.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out start) &&
47 ushort.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out end) &&
48 ushort.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out top) &&
49 ushort.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out bottom))
51 return GenerateIL(module, start, end, top, bottom);
53 else if (1 == thickness.Length)
56 ushort.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out v);
57 return GenerateIL(module, v, v, v, v);
61 throw new XamlParseException($"Cannot convert \"{value}\" into Position", node);