CanConvertFrom() public method

Returns True when sourceType is a String or Int32.
public CanConvertFrom ( ITypeDescriptorContext context, Type sourceType ) : bool
context ITypeDescriptorContext Additional context for conversion.
sourceType System.Type The type of the source object.
return bool
Esempio n. 1
0
        public void ConvertFromStringPropertyName()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom("UTF8");
            Assert.AreEqual<Encoding>(Encoding.UTF8, value, "Could not convert from a string.");
        }
Esempio n. 2
0
        public void ConvertFromNull()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom(null);
            Assert.AreEqual<Encoding>(Encoding.Default, value, "Could not convert from a null string.");
        }
Esempio n. 3
0
        public void ConvertFromIntegerCodePage()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(int)), "Cannot convert from an integer.");

            var value = (Encoding)converter.ConvertFrom(65001);
            Assert.AreEqual<Encoding>(Encoding.UTF8, value, "Could not convert from an integer.");
        }
Esempio n. 4
0
        public void ConvertFromIntegerCodePage()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(int)), "Cannot convert from an integer.");

            var value = (Encoding)converter.ConvertFrom(65001);

            Assert.AreEqual <Encoding>(Encoding.UTF8, value, "Could not convert from an integer.");
        }
Esempio n. 5
0
        public void ConvertFromNull()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom(null);

            Assert.AreEqual <Encoding>(Encoding.Default, value, "Could not convert from a null string.");
        }
Esempio n. 6
0
        public void ConvertFromStringEncodingName()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom("utf-8");

            Assert.AreEqual <Encoding>(Encoding.UTF8, value, "Could not convert from a string.");
        }