Пример #1
0
        public override object ConvertFromInvariantString(string value)
        {
            // "blurRadius | color [| offset] [| extents]"
            // Examples
            // "1.0 | #AABBCCFF"
            // "6.2 | #AABBCC | 5, 5"
            // "8.0 | #AABBCC | 5, 5 | 7, 8"

            if (string.IsNullOrEmpty(value))
            {
                return(new Shadow(0.0f, Color.Transparent));
            }

            var items = value.Split('|');

            if (items.Length < 2 || items.Length > 4)
            {
                return(new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Shadow)}"));
            }

            var     blurRadius = Single.Parse(items[0].Trim(), CultureInfo.InvariantCulture);
            var     color      = new Color(items[1].Trim());
            Vector2 offset     = null;
            Vector2 extents    = null;

            if (items.Length > 2)
            {
                offset = Vector2TypeConverter.FromString(items[2].Trim());
            }

            if (items.Length == 4)
            {
                extents = Vector2TypeConverter.FromString(items[3].Trim());
            }

            return(new Shadow(blurRadius, color, offset, extents));
        }
Пример #2
0
        public override object ConvertFromInvariantString(string value)
        {
            // "imageUrl [| offset] [| extents]"
            // Examples
            // "*Resource*/image.9.png"
            // "*Resource*/image.9.png | 5, 5"
            // "*Resource*/image.9.png | 5, 5 | 7, 8"

            if (string.IsNullOrEmpty(value))
            {
                return(new ImageShadow(String.Empty));
            }

            var items = value.Split('|');

            if (items.Length < 1 || items.Length > 3)
            {
                return(new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(ImageShadow)}"));
            }

            var     url     = items[0].Trim();
            Vector2 offset  = null;
            Vector2 extents = null;

            if (items.Length > 1)
            {
                offset = Vector2TypeConverter.FromString(items[1].Trim());
            }

            if (items.Length == 3)
            {
                extents = Vector2TypeConverter.FromString(items[2].Trim());
            }

            return(new ImageShadow(url, offset, extents));
        }