ConvertFrom() 공개 메소드

Converts a String or Int32 to an Encoding.
Returns Encoding.Default if the value is null or an empty string.
No could be matched to the string or code page integer.
public ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, object value ) : object
context ITypeDescriptorContext Additional context for conversion.
culture System.Globalization.CultureInfo The culture to use for conversion.
value object The or value to convert.
리턴 object
예제 #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.");
        }
예제 #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.");
        }
예제 #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.");
        }
예제 #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.");
        }
예제 #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.");
        }
예제 #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.");
        }