Пример #1
0
    public static void Main()
    {
        String[] cultureNames = { "", "en-US", "fr-FR", "ru-RU" };
        foreach (var cultureName in cultureNames)
        {
            bool             value     = true;
            CultureInfo      culture   = CultureInfo.CreateSpecificCulture(cultureName);
            BooleanFormatter formatter = new BooleanFormatter(culture);

            string result = string.Format(formatter, "Value for '{0}': {1}", culture.Name, value);
            Console.WriteLine(result);
        }
    }
Пример #2
0
        public void BooleanFormatter()
        {
            var formatter = new BooleanFormatter();
            var result    = formatter.Format(false, 0);

            Assert.Single(result);
            Assert.True(result.ContainsKey(string.Empty), "Should have a single, empty key");
            Assert.Equal("false", result[string.Empty]);

            result = formatter.Format(true, 0);

            Assert.Single(result);
            Assert.True(result.ContainsKey(string.Empty), "Should have a single, empty key");
            Assert.Equal("true", result[string.Empty]);

            Assert.True(formatter.Handles(typeof(bool)), "Should handle boolean");
            Assert.True(formatter.Handles(typeof(Boolean)), "Should handle boolean");

            Assert.False(formatter.Handles(typeof(string)), "Should not handle non-boolean types");
            Assert.False(formatter.Handles(typeof(object)), "Should not handle non-boolean types");
        }