Beispiel #1
0
        public static void ConvertWithConverterFinder()
        {
            var       property  = typeof(Options).GetProperty("DestinationIP");
            var       converter = ConverterFinder.GetConverterForProperty(property);
            IPAddress addr      = (IPAddress)converter.ConvertFromString("1fbf:0:a88:85a3::ac1f");

            Console.WriteLine("ConverterFinder Address: {0}", addr);
        }
        public void GetConverterForProperty_WithNoCustomConverter_ReturnsBaseConverter()
        {
            var expectedType = typeof(Int32Converter);
            var actual       = ConverterFinder
                               .GetConverterForProperty(
                typeof(TestPropertyClass)
                .GetProperty("SomeValue"));

            Assert.IsInstanceOfType(actual, expectedType);
        }
        public void GetConverterForProperty_WithNoDefaultConverterAndCustomConverterAppliedToProperty_ReturnsCustomConverter()
        {
            var expectedType = typeof(CustomClassWithDescriptorConverter);

            var actual = ConverterFinder
                         .GetConverterForProperty(
                typeof(TestPropertyClass)
                .GetProperty("AnotherValue"));

            Assert.IsInstanceOfType(actual, expectedType);
        }
        public void GetConverterForProperty_WithConverterAppliedToProperty_ReturnsCustomConverter()
        {
            var expectedType = typeof(CustomIntConverter);

            var actual = ConverterFinder
                         .GetConverterForProperty(
                typeof(TestPropertyClass)
                .GetProperty("SomeCustomValue"));

            Assert.IsInstanceOfType(actual, expectedType);
        }
        public void GetConverterForProperty_WithObjectInheritingICustomTypeDescriptor_ReturnsCustomConverter()
        {
            var obj          = new ClassWithDescriptor(10);
            var expectedType = typeof(ClassWithDescriptorConverter);

            var actual = ConverterFinder
                         .GetConverterForProperty(
                typeof(TestPropertyClass)
                .GetProperty("OtherValue"),
                obj);

            Assert.IsInstanceOfType(actual, expectedType);
        }