public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }

            if (value.GetType() == typeof(string))
            {
                string text = Convert.ToString(value);

                // "" or "(None)"
                if (text == string.Empty || text == Resources.TEXT_NONE_BR)
                {
                    if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
                    {
                        TopologyRule topologyRule = (TopologyRule)context.Instance;
                        switch (context.PropertyDescriptor.Name)
                        {
                        case "OriginSubtype":
                            return(topologyRule.AllOriginSubtypes ? 0 : -1);

                        case "DestinationSubtype":
                            return(topologyRule.AllDestinationSubtypes ? 0 : -1);

                        default:
                            return(-1);
                        }
                    }
                    return(-1);
                }

                // "(Class)"
                if (text == Resources.TEXT_CLASS_BR)
                {
                    return(0);
                }

                // Subtype Name
                ObjectClass objectClass = this.GetObjectClass(context);
                if (objectClass == null)
                {
                    return(-1);
                }
                Subtype subtype = objectClass.FindSubtype(text);
                if (subtype == null)
                {
                    return(-1);
                }
                return(subtype.SubtypeCode);
            }
            return(base.ConvertFrom(context, culture, value));
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            if (destinationType == typeof(string))
            {
                if (value.GetType() == typeof(int))
                {
                    int         id          = Convert.ToInt32(value);
                    ObjectClass objectClass = this.GetObjectClass(context);
                    if (objectClass == null)
                    {
                        return(Resources.TEXT_NONE_BR);
                    }
                    List <Subtype> subtypes = objectClass.GetSubtypes();
                    if (subtypes.Count == 0)
                    {
                        if (id == -1)
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                        return(Resources.TEXT_CLASS_BR);
                    }

                    if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
                    {
                        TopologyRule topologyRule = (TopologyRule)context.Instance;
                        switch (context.PropertyDescriptor.Name)
                        {
                        case "OriginSubtype":
                            if (topologyRule.OriginSubtype == 0 && topologyRule.AllOriginSubtypes)
                            {
                                return(Resources.TEXT_NONE_BR);
                            }
                            break;

                        case "DestinationSubtype":
                            if (topologyRule.DestinationSubtype == 0 && topologyRule.AllDestinationSubtypes)
                            {
                                return(Resources.TEXT_NONE_BR);
                            }
                            break;
                        }
                    }

                    Subtype subtype = objectClass.FindSubtype(id);
                    if (subtype == null)
                    {
                        return(Resources.TEXT_NONE_BR);
                    }
                    return(subtype.SubtypeName);
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }