예제 #1
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         PropertyGridInspector data = value as PropertyGridInspector;
         if (data != null)
         {
             Type type = data._Data.GetType();
             if (type == typeof(string) || type == typeof(Uri))
             {
                 return(Convert.ToString(data._Data, CultureInfo.InvariantCulture));
             }
             DebuggerDisplayAttribute[] attributes = (DebuggerDisplayAttribute[])type.GetCustomAttributes(typeof(DebuggerDisplayAttribute), true);
             if (attributes.Length == 1)
             {
                 DebuggerDisplayAttribute text = attributes[0];
                 return(Regex.Replace(text.Value, @"\{([^\}]+)\}", delegate(Match match)
                 {
                     try
                     {
                         return Convert.ToString(type.GetProperty(match.Groups[1].Value).GetValue(data._Data, null));
                     }
                     catch (Exception exception)
                     {
                         return "[" + exception.Message + "]";
                     }
                 }));
             }
             return(data._Data.GetType().FullName);
         }
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
예제 #2
0
 public override bool GetPropertiesSupported(ITypeDescriptorContext context)
 {
     if (context != null && context.PropertyDescriptor != null)
     {
         PropertyGridInspector data = context.PropertyDescriptor.GetValue(context.Instance) as PropertyGridInspector;
         if (data == null)
         {
             return(false);
         }
         IDictionary dictionary = data._Data as IDictionary;
         if (dictionary != null && dictionary.Count == 0)
         {
             return(false);
         }
         NameValueCollection collection = data._Data as NameValueCollection;
         if (collection != null && collection.Count == 0)
         {
             return(false);
         }
     }
     return(true);
 }