Beispiel #1
0
        /// <summary>
        /// 将类型转换成字符串
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string) && value != null)
            {
                CPoint point = value as CPoint;
                string str   = string.Format($"{point.PointX},{point.PointY}");
                return(str);
            }

            if (destinationType == typeof(InstanceDescriptor) && value != null)
            {
                ConstructorInfo constructorInfo = typeof(CPoint).GetConstructor(new Type[] { typeof(int), typeof(int) });
                CPoint          point           = value as CPoint;
                return(new InstanceDescriptor(constructorInfo, new object[] { point.PointX, point.PointY }));
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }