public void TestGetInstance_CultureInfo()
 {
     NodaFormatInfo.ClearCache();
     using (CultureSaver.SetCultures(enUs, FailingCultureInfo.Instance))
     {
         var actual = NodaFormatInfo.GetInstance(enGb);
         Assert.AreSame(enGb, actual.CultureInfo);
     }
 }
 public void TestGetInstance_IFormatProvider()
 {
     NodaFormatInfo.ClearCache();
     using (CultureSaver.SetCultures(enUs, FailingCultureInfo.Instance))
     {
         var provider = new EmptyFormatProvider();
         var actual   = NodaFormatInfo.GetInstance(provider);
         Assert.AreSame(enUs, actual.CultureInfo);
     }
 }
 public void TestGetInstance_DateTimeFormatInfo()
 {
     NodaFormatInfo.ClearCache();
     using (CultureSaver.SetCultures(enUs, FailingCultureInfo.Instance))
     {
         var info = NodaFormatInfo.GetInstance(enGb.DateTimeFormat);
         Assert.AreEqual(enGb.DateTimeFormat, info.DateTimeFormat);
         Assert.AreEqual(CultureInfo.InvariantCulture, info.CultureInfo);
     }
 }
        internal string Format(T value, string?patternText, IFormatProvider?formatProvider)
        {
            if (string.IsNullOrEmpty(patternText))
            {
                patternText = defaultFormatPattern;
            }
            NodaFormatInfo formatInfo = NodaFormatInfo.GetInstance(formatProvider);
            IPattern <T>   pattern    = patternParser(formatInfo).ParsePattern(patternText);

            return(pattern.Format(value));
        }
Beispiel #5
0
        internal string Format(T value, string?patternText, IFormatProvider?formatProvider)
        {
            if (string.IsNullOrEmpty(patternText))
            {
                patternText = defaultFormatPattern;
            }
            NodaFormatInfo formatInfo = NodaFormatInfo.GetInstance(formatProvider);
            // TODO(nullable): Work out why Roslyn doesn't know about string.IsNullOrEmpty any more.
            IPattern <T> pattern = patternParser(formatInfo).ParsePattern(patternText !);

            return(pattern.Format(value));
        }
Beispiel #6
0
        internal string Format(T value, string?patternText, IFormatProvider?formatProvider)
        {
            if (string.IsNullOrEmpty(patternText))
            {
                patternText = defaultFormatPattern;
            }
            NodaFormatInfo formatInfo = NodaFormatInfo.GetInstance(formatProvider);
            // Note: string.IsNullOrEmpty isn't annotated in netstandard2.0, hence the use of the
            // null-forgiving operator here. *We* know patternText isn't null.
            IPattern <T> pattern = patternParser(formatInfo).ParsePattern(patternText !);

            return(pattern.Format(value));
        }
 public void TestGetInstance_null()
 {
     NodaFormatInfo.ClearCache();
     using (CultureSaver.SetCultures(enUs, FailingCultureInfo.Instance))
     {
         var info = NodaFormatInfo.GetInstance(null);
         Assert.AreEqual(Thread.CurrentThread.CurrentCulture, info.CultureInfo);
     }
     using (CultureSaver.SetCultures(enGb, FailingCultureInfo.Instance))
     {
         var info = NodaFormatInfo.GetInstance(null);
         Assert.AreEqual(Thread.CurrentThread.CurrentCulture, info.CultureInfo);
     }
 }
 public void TestGetInstance_UnusableType()
 {
     NodaFormatInfo.ClearCache();
     Assert.Throws <ArgumentException>(() => NodaFormatInfo.GetInstance(CultureInfo.InvariantCulture.NumberFormat));
 }