Exemple #1
0
 /// <override></override>
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == null)
     {
         throw new ArgumentNullException("destinationType");
     }
     if (value is string || value == null)
     {
         if (destinationType == typeof(int))
         {
             return(ConvertToLayerId(context, (string)value));
         }
         else if (destinationType == typeof(LayerIds))
         {
             return(ConvertToLayerIds(context, (string)value));
         }
         else
         {
             throw new NotSupportedException();
         }
     }
     else if (value is int)
     {
         if (destinationType == typeof(LayerIds))
         {
             return(Layer.ConvertToLayerIds((int)value));
         }
         else if (destinationType == typeof(string))
         {
             return(ConvertToLayerName(context, (int)value));
         }
         else
         {
             throw new NotSupportedException();
         }
     }
     else if (value is LayerIds)
     {
         if (destinationType == typeof(int))
         {
             return(Layer.ConvertToLayerId((LayerIds)value));
         }
         else if (destinationType == typeof(string))
         {
             string result = String.Empty;
             foreach (int id in LayerHelper.GetAllLayerIds((LayerIds)value))
             {
                 result += string.Format("{0}{1}",
                                         String.IsNullOrEmpty(result) ? String.Empty : ListSeparatorChar + " ",
                                         ConvertToLayerName(context, id)
                                         );
             }
             return(result);
         }
         else
         {
             throw new NotSupportedException();
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }