Esempio n. 1
0
        private void ApplyTornEdgeEffectValues(string valuesString, TornEdgeEffect effect)
        {
            var values = valuesString.Split('|');

            foreach (var nameValuePair in values)
            {
                var pair = nameValuePair.Split(':');
                switch (pair[0])
                {
                case "GenerateShadow":
                    if (bool.TryParse(pair[1], out var generateShadow))
                    {
                        effect.GenerateShadow = generateShadow;
                    }
                    break;

                case "ToothHeight":
                    if (int.TryParse(pair[1], out var toothHeight))
                    {
                        effect.ToothHeight = toothHeight;
                    }
                    break;

                case "HorizontalToothRange":
                    if (int.TryParse(pair[1], out var horizontalToothRange))
                    {
                        effect.HorizontalToothRange = horizontalToothRange;
                    }
                    break;

                case "VerticalToothRange":
                    if (int.TryParse(pair[1], out var verticalToothRange))
                    {
                        effect.VerticalToothRange = verticalToothRange;
                    }
                    break;

                case "Edges":
                    var edges = pair[1].Split(',');
                    if (bool.TryParse(edges[0], out var edge))
                    {
                        effect.Edges[0] = edge;
                    }
                    if (bool.TryParse(edges[1], out edge))
                    {
                        effect.Edges[1] = edge;
                    }
                    if (bool.TryParse(edges[2], out edge))
                    {
                        effect.Edges[2] = edge;
                    }
                    if (bool.TryParse(edges[3], out edge))
                    {
                        effect.Edges[3] = edge;
                    }
                    break;
                }
            }
        }
Esempio n. 2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // to string
            if (destinationType == typeof(string))
            {
                var sb = new StringBuilder();
                switch (value)
                {
                case TornEdgeEffect tornEdgeEffect:
                    RetrieveDropShadowEffectValues(tornEdgeEffect, sb);
                    sb.Append("|");
                    RetrieveTornEdgeEffectValues(tornEdgeEffect, sb);
                    return(sb.ToString());

                case DropShadowEffect dropShadowEffect:
                    RetrieveDropShadowEffectValues(dropShadowEffect, sb);
                    return(sb.ToString());
                }
            }
            // from string
            if (!(value is string settings))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            if (destinationType == typeof(DropShadowEffect))
            {
                var effect = new DropShadowEffect();
                ApplyDropShadowEffectValues(settings, effect);
                return(effect);
            }
            if (destinationType == typeof(TornEdgeEffect))
            {
                var effect = new TornEdgeEffect();
                ApplyDropShadowEffectValues(settings, effect);
                ApplyTornEdgeEffectValues(settings, effect);
                return(effect);
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Esempio n. 3
0
 private void RetrieveTornEdgeEffectValues(TornEdgeEffect effect, StringBuilder sb)
 {
     sb.AppendFormat("GenerateShadow:{0}|ToothHeight:{1}|HorizontalToothRange:{2}|VerticalToothRange:{3}|Edges:{4},{5},{6},{7}", effect.GenerateShadow, effect.ToothHeight,
                     effect.HorizontalToothRange, effect.VerticalToothRange, effect.Edges[0], effect.Edges[1], effect.Edges[2], effect.Edges[3]);
 }