public static string JCap(StiCap cap)
            {
                var builder = new StringBuilder();

                // Width
                if (cap.Width != 10)
                {
                    builder.Append(cap.Width);
                }
                builder.Append(";");

                // Height
                if (cap.Height != 10)
                {
                    builder.Append(cap.Height);
                }
                builder.Append(";");

                // Style
                if (cap.Style != StiCapStyle.None)
                {
                    builder.Append(cap.Style.ToString());
                }
                builder.Append(";");

                // Color
                builder.Append(JColor(cap.Color, Color.Black));

                return(builder.ToString());
            }
            public static StiCap JCap(string text)
            {
                var values = text.Split(';');
                var cap    = new StiCap();

                if (values.Length != 4)
                {
                    throw new Exception("Parsing Error");
                }

                if (!string.IsNullOrEmpty(values[0]))
                {
                    cap.Width = int.Parse(values[0]);
                }

                if (!string.IsNullOrEmpty(values[1]))
                {
                    cap.Height = int.Parse(values[1]);
                }

                if (!string.IsNullOrEmpty(values[2]))
                {
                    cap.Style = (StiCapStyle)Enum.Parse(typeof(StiCapStyle), values[2]);
                }

                if (!string.IsNullOrEmpty(values[3]))
                {
                    cap.Color = Color(values[3]);
                }

                return(cap);
            }
예제 #3
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
                                         object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                if (value == null)
                {
                    return("null");
                }
                else
                {
                    StiCap cap = value as StiCap;
                    return(StiLocalization.Get("PropertyEnum", typeof(StiCapStyle).Name + Enum.GetName(typeof(StiCapStyle), cap.Style), false));
                }
            }

            if (destinationType == typeof(InstanceDescriptor) && value != null)
            {
                #region StiCap
                StiCap cap = (StiCap)value;


                Type[] types = new Type[] {
                    typeof(int),
                    typeof(StiCapStyle),
                    typeof(int),
                    typeof(bool),
                    typeof(Color)
                };

                ConstructorInfo info = typeof(StiCap).GetConstructor(types);
                if (info != null)
                {
                    object[] objs = new object[]        {
                        cap.Width,
                        cap.Style,
                        cap.Height,
                        cap.Fill,
                        cap.Color
                    };

                    return(CreateNewInstanceDescriptor(info, objs));
                }
                #endregion
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }