Ejemplo n.º 1
0
        public IEnumerable <Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
        {
            var module = context.Body.Method.Module;

            if (!string.IsNullOrEmpty(value))
            {
                int x, y;
                var thickness = value.Split(',');

                foreach (var thick in thickness)
                {
                    if (null != NodeILExtensions.GetDPValueSubFix(thick))
                    {
                        return(null);
                    }
                }

                if (int.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) &&
                    int.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y))
                {
                    return(GenerateIL(module, x, y));
                }
            }

            throw new XamlParseException($"Cannot convert \"{value}\" into Size2D", node);
        }
Ejemplo n.º 2
0
        public IEnumerable <Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
        {
            var module = context.Body.Method.Module;

            if (string.IsNullOrEmpty(value))
            {
                throw new XamlParseException($"Cannot convert \"{value}\" into Rectangle", node);
            }
            double x, y, w, h;
            var    xywh = value.Split(',');

            foreach (var thick in xywh)
            {
                if (null != NodeILExtensions.GetDPValueSubFix(thick))
                {
                    return(null);
                }
            }

            if (xywh.Length != 4 ||
                !double.TryParse(xywh [0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) ||
                !double.TryParse(xywh [1], NumberStyles.Number, CultureInfo.InvariantCulture, out y) ||
                !double.TryParse(xywh [2], NumberStyles.Number, CultureInfo.InvariantCulture, out w) ||
                !double.TryParse(xywh [3], NumberStyles.Number, CultureInfo.InvariantCulture, out h))
            {
                throw new XamlParseException($"Cannot convert \"{value}\" into Rectangle", node);
            }

            return(GenerateIL(x, y, w, h, module));
        }
Ejemplo n.º 3
0
        public IEnumerable <Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
        {
            var module = context.Body.Method.Module;

            if (string.IsNullOrEmpty(value))
            {
                throw new XamlParseException($"Cannot convert \"{value}\" into Rectangle", node);
            }

            double x = -1, y = -1, w = -1, h = -1;
            bool   hasX, hasY, hasW, hasH;
            var    xywh = value.Split(',');

            foreach (var thick in xywh)
            {
                if (null != NodeILExtensions.GetDPValueSubFix(thick))
                {
                    return(null);
                }
            }

            if (xywh.Length != 2 && xywh.Length != 4)
            {
                throw new XamlParseException($"Cannot convert \"{value}\" into Rectangle", node);
            }

            hasX = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh [0], NumberStyles.Number, CultureInfo.InvariantCulture, out x);
            hasY = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh [1], NumberStyles.Number, CultureInfo.InvariantCulture, out y);
            hasW = xywh.Length == 4 && double.TryParse(xywh [2], NumberStyles.Number, CultureInfo.InvariantCulture, out w);
            hasH = xywh.Length == 4 && double.TryParse(xywh [3], NumberStyles.Number, CultureInfo.InvariantCulture, out h);

            if (!hasW && xywh.Length == 4 && string.Compare("AutoSize", xywh [2].Trim(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                hasW = true;
                //w = AbsoluteLayout.AutoSize;
            }

            if (!hasH && xywh.Length == 4 && string.Compare("AutoSize", xywh [3].Trim(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                hasH = true;
                //h = AbsoluteLayout.AutoSize;
            }

            if (hasX && hasY && xywh.Length == 2)
            {
                hasW = true;
                //w = AbsoluteLayout.AutoSize;
                hasH = true;
                //h = AbsoluteLayout.AutoSize;
            }

            if (!hasX || !hasY || !hasW || !hasH)
            {
                throw new XamlParseException($"Cannot convert \"{value}\" into Rectangle", node);
            }

            return(GenerateIL(x, y, w, h, module));
        }
Ejemplo n.º 4
0
        public IEnumerable <Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
        {
            var module = context.Body.Method.Module;

            var thickness = value.Split(',');

            foreach (var thick in thickness)
            {
                if (null != NodeILExtensions.GetDPValueSubFix(thick))
                {
                    return(null);
                }
            }

            if (3 == thickness.Length)
            {
                double x, y, z;

                if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) &&
                    double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y) &&
                    double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out z))
                {
                    return(GenerateIL(module, x, y, z));
                }
            }
            else if (2 == thickness.Length)
            {
                double x, y;

                if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) &&
                    double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y))
                {
                    return(GenerateIL(module, x, y, 0));
                }
            }
            else if (1 == thickness.Length)
            {
                if (value.Contains("."))
                {
                    string[] parts = value.Split('.');
                    if (parts.Length == 2 && (parts[0].Trim() == "ParentOrigin" || parts[0].Trim() == "PivotPoint"))
                    {
                        string position = parts[parts.Length - 1].Trim();
                        return(ConvertToPoint(position, context, node));
                    }
                }
                else
                {
                    return(ConvertToPoint(value, context, node));
                }
            }

            throw new XamlParseException($"Cannot convert \"{value}\" into Position", node);
        }
Ejemplo n.º 5
0
        public IEnumerable <Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
        {
            var module = context.Body.Method.Module;

            if (!string.IsNullOrEmpty(value))
            {
                double l, t, r, b;
                var    thickness = value.Split(',');

                foreach (var thick in thickness)
                {
                    if (null != NodeILExtensions.GetDPValueSubFix(thick))
                    {
                        return(null);
                    }
                }

                switch (thickness.Length)
                {
                case 1:
                    if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l))
                    {
                        return(GenerateIL(module, l));
                    }
                    break;

                case 2:
                    if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&
                        double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t))
                    {
                        return(GenerateIL(module, l, t));
                    }
                    break;

                case 4:
                    if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&
                        double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t) &&
                        double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out r) &&
                        double.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out b))
                    {
                        return(GenerateIL(module, l, t, r, b));
                    }
                    break;
                }
            }
            throw new XamlParseException($"Cannot convert \"{value}\" into Thickness", node);
        }
Ejemplo n.º 6
0
        public IEnumerable <Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
        {
            var module = context.Body.Method.Module;

            if (!string.IsNullOrEmpty(value))
            {
                var thickness = value.Split(',');

                foreach (var thick in thickness)
                {
                    if (null != NodeILExtensions.GetDPValueSubFix(thick))
                    {
                        return(null);
                    }
                }

                if (4 == thickness.Length)
                {
                    ushort start, end, top, bottom;

                    if (ushort.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out start) &&
                        ushort.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out end) &&
                        ushort.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out top) &&
                        ushort.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out bottom))
                    {
                        return(GenerateIL(module, start, end, top, bottom));
                    }
                }
                else if (1 == thickness.Length)
                {
                    ushort v;
                    ushort.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out v);
                    return(GenerateIL(module, v, v, v, v));
                }
            }

            throw new XamlParseException($"Cannot convert \"{value}\" into Position", node);
        }