Example #1
0
        /// <summary>
        /// Tries to find a Converter using its static resource name.
        /// </summary>
        /// <param name="converterName"></param>
        /// <returns>The converter, or a NullConverter instance.</returns>
        public static IValueConverter FindConverter(string converterName)
        {
            // Get instead of Find as we want to reproduce the Jupiter behavior : is the resource is missing we get an exception.
            var converter = Registry.FindResource(converterName) as IValueConverter;

            if (converter == null)
            {
                Registry.Log().ErrorFormat("Resource [{0}] does not implement IValueConverter.", converterName);

                // Reproduce the beahvior on Jupiter : if the resource does not implements IValueConverter,
                // nothing appear in the view.
                converter = new NullConverter();
            }

            return(converter);
        }
        public void TestNullConverter()
        {
            var converter = new NullConverter();

            converter.TreatEmptyStringAsNull = false;

            Assert.AreEqual(true, converter.Convert(null, null, null, null));
            Assert.AreEqual(false, converter.Convert(1, null, null, null));
            Assert.AreEqual(false, converter.Convert(new object(), null, null, null));
            Assert.AreEqual(false, converter.Convert(string.Empty, null, null, null));

            converter.TreatEmptyStringAsNull = true;

            Assert.AreEqual(true, converter.Convert(null, null, null, null));
            Assert.AreEqual(false, converter.Convert(1, null, null, null));
            Assert.AreEqual(false, converter.Convert(new object(), null, null, null));
            Assert.AreEqual(true, converter.Convert(string.Empty, null, null, null));
        }
 private void WhenCreating()
 {
     ThenConverter = new NullConverter();
 }