ConvertFrom() публичный Метод

Converts a String in the short form like "omus" to a LoggingPolicies enumeration.
The short form string contains invalid characters.
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 value to convert.
Результат object
Пример #1
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"); });
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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"); });
        }
Пример #6
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);
        }