예제 #1
0
        public void CanConvertFromFalse(Type type)
        {
            var conv = new ColorConverter();

            Assert.False(conv.CanConvertFrom(type));
            Assert.False(conv.CanConvertFrom(null, type));
        }
예제 #2
0
        public static Brush GetBrush(this string colorString, Color defaultColor)
        {
            if (colorString != null)
            {
                ColorConverter converter = new ColorConverter();

                if (converter.CanConvertFrom(typeof(string)))
                {
                    try
                    {
                        Color color = (Color)converter.ConvertFrom(null, null, colorString);
                        return(new SolidColorBrush(color));
                    }
                    catch (Exception)
                    {
                        cerr.WriteLine($"color string: \"{colorString}\" not supported");
                    }
                }
            }

            return(new SolidColorBrush(defaultColor));
        }
 public void CanConvertFrom()
 {
     Assert.IsTrue(colconv.CanConvertFrom(typeof(String)), "CCF#1");
     Assert.IsTrue(colconv.CanConvertFrom(null, typeof(String)), "CCF#1a");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(Rectangle)), "CCF#2");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(RectangleF)), "CCF#3");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(Point)), "CCF#4");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(PointF)), "CCF#5");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(Color)), "CCF#6");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(SizeF)), "CCF#7");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(Object)), "CCF#8");
     Assert.IsFalse(colconv.CanConvertFrom(null, typeof(int)), "CCF#9");
     Assert.IsTrue(colconv.CanConvertFrom(null, typeof(InstanceDescriptor)), "CCF#10");
 }