Пример #1
0
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (context != null && context.Container != null)
            {
                return(base.ConvertFrom(context, culture, value));
            }

            if (value is string)
            {
                if (noneString.Equals(value))
                {
                    return(null);
                }

                try
                {
                    string[] tokens = (value as string).Split('|');

                    if (tokens.Length == 0 || string.IsNullOrEmpty(tokens[0]))
                    {
                        return(null);
                    }
                    if (shownError)
                    {
                        return(null);
                    }
                    ElementShape elementShape = null;
                    Type         shapeType    = RadTypeResolver.Instance.GetTypeByName(tokens[0].Trim());
                    if (shapeType == null)
                    {
                        return(null);
                    }
                    if (!(typeof(ElementShape)).IsAssignableFrom(shapeType))
                    {
                        VSCacheError.ShowVSCacheError((typeof(ElementShape)).Assembly, shapeType.Assembly);
                        shownError = true;
                    }
                    else
                    {
                        elementShape = (ElementShape)Activator.CreateInstance(shapeType);
                        if (tokens.Length > 1)
                        {
                            elementShape.DeserializeProperties(tokens[1]);
                        }
                    }
                    return(elementShape);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error deserializing custom shape: " + ex.ToString());
                    return(null);
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }
Пример #2
0
        public override object ConvertFrom(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value)
        {
            if (context != null && context.Container != null)
            {
                return(base.ConvertFrom(context, culture, value));
            }
            if (!(value is string))
            {
                return(base.ConvertFrom(context, culture, value));
            }
            if ("(none)".Equals(value))
            {
                return((object)null);
            }
            try
            {
                string[] strArray = (value as string).Split('|');
                if (strArray.Length == 0 || string.IsNullOrEmpty(strArray[0]) || ElementShapeConverter.shownError)
                {
                    return((object)null);
                }
                ElementShape elementShape = (ElementShape)null;
                string       str          = strArray[0].Trim();
                System.Type  type         = Assembly.GetExecutingAssembly().GetType(str, false, false);
                if ((object)type == null)
                {
                    switch (str)
                    {
                    case "Telerik.WinControls.Tests.DonutShape":
                        type = typeof(DonutShape);
                        break;

                    case "Telerik.WinControls.Tests.QAShape":
                        type = typeof(QAShape);
                        break;

                    case "Telerik.WinControls.EllipseShape":
                        type = typeof(EllipseShape);
                        break;

                    case "Telerik.WinControls.RoundRectShape":
                        type = typeof(RoundRectShape);
                        break;

                    case "Telerik.WinControls.ChamferedRectShape":
                        type = typeof(ChamferedRectShape);
                        break;

                    case "Telerik.WinControls.UI.OfficeShape":
                        type = typeof(OfficeShape);
                        break;

                    case "Telerik.WinControls.UI.TabIEShape":
                        type = typeof(TabIEShape);
                        break;

                    case "Telerik.WinControls.UI.TabOffice12Shape":
                        type = typeof(TabOffice12Shape);
                        break;

                    case "Telerik.WinControls.UI.TabVsShape":
                        type = typeof(TabVsShape);
                        break;

                    case "Telerik.WinControls.UI.TrackBarDThumbShape":
                        type = typeof(TrackBarDThumbShape);
                        break;

                    case "Telerik.WinControls.UI.TrackBarLThumbShape":
                        type = typeof(TrackBarLThumbShape);
                        break;

                    case "Telerik.WinControls.UI.TrackBarRThumbShape":
                        type = typeof(TrackBarRThumbShape);
                        break;

                    case "Telerik.WinControls.UI.TrackBarUThumbShape":
                        type = typeof(TrackBarUThumbShape);
                        break;
                    }
                }
                if ((object)type == null)
                {
                    type = RadTypeResolver.Instance.GetTypeByName(str);
                }
                if ((object)type == null)
                {
                    return((object)null);
                }
                if (!typeof(ElementShape).IsAssignableFrom(type))
                {
                    VSCacheError.ShowVSCacheError(typeof(ElementShape).Assembly, type.Assembly);
                    ElementShapeConverter.shownError = true;
                }
                else
                {
                    elementShape = (ElementShape)Activator.CreateInstance(type);
                    if (strArray.Length > 1)
                    {
                        elementShape.DeserializeProperties(strArray[1]);
                    }
                }
                return((object)elementShape);
            }
            catch (Exception ex)
            {
                int num = (int)MessageBox.Show("Error deserializing custom shape: " + ex.ToString());
                return((object)null);
            }
        }