Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using static System.Console;
- namespace System.Runtime.CompilerServices
- {
- public class FormattableStringFactory
- {
- public static IFormattable Create(string messageFormat, params object[] args)
- {
- return new FormattableString(messageFormat, args);
- }
- public class FormattableString : IFormattable
- {
- private readonly string _messageFormat;
- private readonly object[] _args;
- public FormattableString(string messageFormat, object[] args)
- {
- _messageFormat = messageFormat;
- _args = args;
- }
- public string ToString(string format, IFormatProvider formatProvider)
- {
- return string.Format(formatProvider, _messageFormat, _args);
- }
- }
- }
- }
- namespace CsTests
- {
- public static class FormattableExt
- {
- public static string AsFr(this IFormattable format)
- {
- return format.ToString(null, CultureInfo.GetCultureInfo("fr-FR"));
- }
- }
- class Program
- {
- static string FR(IFormattable src)
- {
- return src.ToString(null, CultureInfo.GetCultureInfo("fr-FR"));
- }
- static string US(IFormattable src)
- {
- return src.ToString(null, CultureInfo.GetCultureInfo("en-US"));
- }
- static string INV(IFormattable src)
- {
- return src.ToString(null, CultureInfo.InvariantCulture);
- }
- private static void Main(string[] args)
- {
- WriteLine($"Number: {999 * 2:N}; the current date is {DateTime.Now + TimeSpan.FromHours(12)}");
- WriteLine(FR($"Number: {999 * 2:N}; the current date is {DateTime.Now + TimeSpan.FromHours(12)}"));
- WriteLine(US($"Number: {999 * 2:N}; the current date is {DateTime.Now + TimeSpan.FromHours(12)}"));
- WriteLine(INV($"Number: {999 * 2:N}; the current date is {DateTime.Now + TimeSpan.FromHours(12)}"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement