CanConvertFrom() public method

Returns True when sourceType is a String.
public CanConvertFrom ( ITypeDescriptorContext context, Type sourceType ) : bool
context ITypeDescriptorContext Additional context for conversion.
sourceType System.Type The type of the source object.
return bool
        public void ConvertInvalidStringToLoggingModes()
        {
            var converter = new LoggingPoliciesConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsFalse(converter.CanConvertFrom(this.GetType()));

            // The append logging command line option is not supported in the registry policy.
            ExceptionAssert.Throws<ArgumentException>(() => { var mode = (LoggingPolicies)converter.ConvertFrom("*vx!+"); });

            // Bogus command line options.
            ExceptionAssert.Throws<ArgumentException>(() => { var mode = (LoggingPolicies)converter.ConvertFrom("jkl"); });
        }
示例#2
0
        public void ConvertInvalidStringToLoggingModes()
        {
            var converter = new LoggingPoliciesConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsFalse(converter.CanConvertFrom(this.GetType()));

            // The append logging command line option is not supported in the registry policy.
            ExceptionAssert.Throws <ArgumentException>(() => { var mode = (LoggingPolicies)converter.ConvertFrom("*vx!+"); });

            // Bogus command line options.
            ExceptionAssert.Throws <ArgumentException>(() => { var mode = (LoggingPolicies)converter.ConvertFrom("jkl"); });
        }
        public void ConvertNamesToLoggingModes()
        {
            var converter = new LoggingPoliciesConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsFalse(converter.CanConvertFrom(this.GetType()));

            var mode = (LoggingPolicies)converter.ConvertFrom(LoggingPoliciesConverterTests.DefaultString);
            Assert.AreEqual(LoggingPoliciesConverterTests.Default, mode);

            // Used mixed casing to test default enumeration parsing.
            mode = (LoggingPolicies)converter.ConvertFrom(LoggingPoliciesConverterTests.DefaultString + ", flushEACHline");
            Assert.AreEqual(LoggingPoliciesConverterTests.Default | LoggingPolicies.FlushEachLine, mode);
        }
示例#4
0
        public void ConvertNamesToLoggingModes()
        {
            var converter = new LoggingPoliciesConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsFalse(converter.CanConvertFrom(this.GetType()));

            var mode = (LoggingPolicies)converter.ConvertFrom(LoggingPoliciesConverterTests.DefaultString);

            Assert.AreEqual(LoggingPoliciesConverterTests.Default, mode);

            // Used mixed casing to test default enumeration parsing.
            mode = (LoggingPolicies)converter.ConvertFrom(LoggingPoliciesConverterTests.DefaultString + ", flushEACHline");
            Assert.AreEqual(LoggingPoliciesConverterTests.Default | LoggingPolicies.FlushEachLine, mode);
        }
示例#5
0
        public void ConvertShortFormToLoggingModes()
        {
            var converter = new LoggingPoliciesConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsFalse(converter.CanConvertFrom(this.GetType()));

            var mode = (LoggingPolicies)converter.ConvertFrom("oiceWARMUP");

            Assert.AreEqual <LoggingPolicies>(Default, mode);

            mode = (LoggingPolicies)converter.ConvertFrom("*vx");
            Assert.AreEqual <LoggingPolicies>(LoggingPolicies.All, mode);

            mode = (LoggingPolicies)converter.ConvertFrom("*vx!");
            Assert.AreEqual <LoggingPolicies>(LoggingPolicies.All | LoggingPolicies.FlushEachLine, mode);
        }
        public void ConvertShortFormToLoggingModes()
        {
            var converter = new LoggingPoliciesConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsFalse(converter.CanConvertFrom(this.GetType()));

            var mode = (LoggingPolicies)converter.ConvertFrom("oiceWARMUP");
            Assert.AreEqual<LoggingPolicies>(Default, mode);

            mode = (LoggingPolicies)converter.ConvertFrom("*vx");
            Assert.AreEqual<LoggingPolicies>(LoggingPolicies.All, mode);

            mode = (LoggingPolicies)converter.ConvertFrom("*vx!");
            Assert.AreEqual<LoggingPolicies>(LoggingPolicies.All | LoggingPolicies.FlushEachLine, mode);
        }