//Format specifiers with invariant culture public static void CustomStringFormatingUsingStringFomatable() { var myInterdPolatedString = $"{x}, How is your day? \n {y}"; /*passing the string this way does not work*/ string formatAble = FormattableString.Invariant($"{x}, How is your day?\n{y}."); string formatAble2 = FormattableString.CurrentCulture($"{x}, How is your day?\n{y}."); Console.WriteLine(formatAble2); }
public static void CurrentCulture_ImplicityAndExplicitMethodsReturnSameString() { double d = 123.456; string text1 = $"This will be formatted using current culture {d}"; string text2 = FormattableString.CurrentCulture($"This will be formatted using current culture {d}"); Assert.Equal(text1, text2); }
public static void CurrentCulture_DutchCulture_FormatsDoubleBasedOnCurrentCulture() { var dutchCulture = new CultureInfo("nl"); using (new ThreadCultureChange(dutchCulture)) { double d = 123.456; string expected = string.Format(dutchCulture, "Dutch decimal separator is comma {0}", d); string actual = FormattableString.CurrentCulture($"Dutch decimal separator is comma {d}"); Assert.Equal(expected, actual); } }
public static void CurrentCulture_DutchCulture_FormatsDoubleBasedOnCurrentCulture() { RemoteExecutor.Invoke(() => { var dutchCulture = new CultureInfo("nl"); CultureInfo.CurrentCulture = dutchCulture; double d = 123.456; string expected = string.Format(dutchCulture, "Dutch decimal separator is comma {0}", d); string actual = FormattableString.CurrentCulture($"Dutch decimal separator is comma {d}"); Assert.Equal(expected, actual); return(RemoteExecutor.SuccessExitCode); }).Dispose(); }
public static void CurrentCulture_Null_ThrowsArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("formattable", () => FormattableString.CurrentCulture(null)); }