コード例 #1
0
        public static void Main(string[] args)
        {
            {
                #region Snippet_A1
                IPluralRules rules = PluralRulesResolver.Default.Resolve("Unicode.CLDR35");
                ILine        root  = LineRoot.Global.PluralRules(rules);
                #endregion Snippet_A1
            }
            {
                #region Snippet_A2
                ILine root = LineRoot.Global.PluralRules("Unicode.CLDR35");
                #endregion Snippet_A2
            }
            {
                #region Snippet_A3
                ILine root = LineRoot.Global.PluralRules("[Category=cardinal,Case=zero,Optional=1]n=0[Category=cardinal,Case=one]n=1[Category=cardinal,Case=other]true");
                #endregion Snippet_A3
            }

            {
                #region Snippet_0a
                IAsset    asset = LineReaderMap.Default.FileAsset("PluralityExample0a.xml");
                ILineRoot root  = new LineRoot(asset);
                ILine     key   = root.Key("Cats").Format("{0} cat(s)");

                // Print with the default string (without culture policy)
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(key.Value(cats));
                }

                // Print Culture "en"
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(key.Culture("en").Value(cats));
                }

                // Print Culture "fi"
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(key.Culture("fi").Value(cats));
                }
                #endregion Snippet_0a
            }
            {
                #region Snippet_0a2
                IAsset    asset = LineReaderMap.Default.FileAsset("PluralityExample0a.json");
                ILineRoot root  = new LineRoot(asset);
                ILine     line  = root.Key("Cats").Format("{0} cat(s)");

                // Print with the default string (without culture policy)
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Value(cats));
                }

                // Print Culture "en"
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Culture("en").Value(cats));
                }

                // Print Culture "fi"
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Culture("fi").Value(cats));
                }
                #endregion Snippet_0a2
            }
            {
                #region Snippet_0a3
                IAsset    asset = LineReaderMap.Default.FileAsset("PluralityExample0a.ini");
                ILineRoot root  = new LineRoot(asset);
                ILine     key   = root.Key("Cats").Format("{0} cat(s)");

                // Print with the default string (without culture policy)
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(key.Value(cats));
                }

                // Print Culture "en"
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(key.Culture("en").Value(cats));
                }

                // Print Culture "fi"
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(key.Culture("fi").Value(cats));
                }
                #endregion Snippet_0a3
            }

            {
                #region Snippet_0b
                ILineRoot root = new LineRoot();
                ILine     line = root.Key("Cats")
                                 .PluralRules("Unicode.CLDR35")
                                 .Format("{cardinal:0} cat(s)") // Default string
                                 .Inline("N:zero", "no cats")
                                 .Inline("N:one", "a cat")
                                 .Inline("N:other", "{0} cats");
                #endregion Snippet_0b
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Value(cats));
                }
            }

            {
                #region Snippet_0c
                ILineRoot root = new LineRoot();
                ILine     line = root.Key("Cats")
                                 .PluralRules("Unicode.CLDR35")
                                 .Format("{0} cat(s)") // Default string
                                 .Inline("Culture:en", "{cardinal:0} cat(s)")
                                 .Inline("Culture:en:N:zero", "no cats")
                                 .Inline("Culture:en:N:one", "a cat")
                                 .Inline("Culture:en:N:other", "{0} cats")
                                 .Inline("Culture:fi", "{cardinal:0} kissa(a)")
                                 .Inline("Culture:fi:N:zero", "ei kissoja")
                                 .Inline("Culture:fi:N:one", "yksi kissa")
                                 .Inline("Culture:fi:N:other", "{0} kissaa");

                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Culture("en").Value(cats));
                }
                #endregion Snippet_0c
            }

            {
                // CLDR35 has rules for "" culture
                #region Snippet_1a
                IAsset asset = LineReaderMap.Default.FileAsset("PluralityExample0b.xml");
                ILine  key   = new LineRoot(asset).Key("Cats");

                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(key.Value(cats));
                }
                #endregion Snippet_1a
            }


            {
                // Plurality permutations for argument 0
                #region Snippet_2
                ILine line = LineRoot.Global.Key("CatsDogs")
                             .PluralRules("Unicode.CLDR35")
                             .Format("{cardinal:0} cat(s) and {1} dog(s)")
                             .Inline("N:zero", "no cats and {1} dog(s)")
                             .Inline("N:one", "a cat and {1} dog(s)")
                             .Inline("N:other", "{0} cats and {1} dog(s)");

                for (int cats = 0; cats <= 2; cats++)
                {
                    for (int dogs = 0; dogs <= 2; dogs++)
                    {
                        Console.WriteLine(line.Value(cats, dogs));
                    }
                }
                #endregion Snippet_2
            }

            {
                // Plurality permutations for argument 0
                #region Snippet_3
                IAsset asset = LineReaderMap.Default.FileAsset("PluralityExample1.xml");
                ILine  key   = new LineRoot(asset).Key("CatsDogs");

                for (int cats = 0; cats <= 2; cats++)
                {
                    for (int dogs = 0; dogs <= 2; dogs++)
                    {
                        Console.WriteLine(key.Value(cats, dogs));
                    }
                }
                #endregion Snippet_3
            }

            {
                // Plurality permutations for argument 0 and argument 1
                #region Snippet_5
                IAsset    asset = LineReaderMap.Default.FileAsset("PluralityExample2.xml");
                ILineRoot root  = new LineRoot(asset);
                ILine     key   = root.Key("CatsDogs").Format("{0} cat(s) and {1} dog(s)");

                for (int cats = 0; cats <= 2; cats++)
                {
                    for (int dogs = 0; dogs <= 2; dogs++)
                    {
                        Console.WriteLine(key.Culture("en").Value(cats, dogs));
                    }
                }
                #endregion Snippet_5
            }
            {
                // Plurality for 4 arguments
                #region Snippet_6
                IAsset asset = LineReaderMap.Default.FileAsset("PluralityExample4.xml");
                ILine  key   = new LineRoot(asset).Key("CatsDogsPoniesHorses");

                for (int cats = 0; cats <= 2; cats++)
                {
                    for (int dogs = 0; dogs <= 2; dogs++)
                    {
                        for (int ponies = 0; ponies <= 2; ponies++)
                        {
                            for (int horses = 0; horses <= 2; horses++)
                            {
                                Console.WriteLine(key.Value(cats, dogs, ponies, horses));
                            }
                        }
                    }
                }
                #endregion Snippet_6
            }
            {
                // Plural expression in localization file
                // [Category=cardinal,Case=zero,Optional=1]n=0[Category=cardinal,Case=one]n=1[Category=cardinal,Case=other]true
                #region Snippet_7
                IAsset asset = LineReaderMap.Default.FileAsset("PluralityExample5.xml");
                ILine  key   = new LineRoot(asset).Key("CatsDogs");

                for (int cats = 0; cats <= 2; cats++)
                {
                    for (int dogs = 0; dogs <= 2; dogs++)
                    {
                        Console.WriteLine(key.Value(cats, dogs));
                    }
                }
                #endregion Snippet_7
            }
            {
                #region Snippet_8
                #endregion Snippet_8
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            // 1. Line
            {
                #region Snippet_1a
                ILine key = LineRoot.Global.PluralRules("Unicode.CLDR35").Key("Key").Format("Hello, {0}");
                #endregion Snippet_1a
            }

            {
                #region Snippet_1b
                ILineRoot root       = new LineRoot();
                ILine     hint1      = root.PluralRules("Unicode.CLDR35");
                ILine     section1   = hint1.Section("Section2");
                ILine     section1_1 = hint1.Section("Section1.1");
                ILine     key1_1_1   = section1_1.Key("Key1");
                ILine     key1_1_2   = section1_1.Key("Key2");
                ILine     value1_1_1 = key1_1_1.Format("Hello, {0}");
                // ...
                #endregion Snippet_1b
            }

            // 2. Parts
            {
                #region Snippet_2a
                IAsset resourceAsset = new ResourceDictionary(new Dictionary <ILine, byte[]>());
                ILine  line          = LineRoot.Global.Asset(resourceAsset);
                #endregion Snippet_2a
            }
            {
                #region Snippet_2b
                ILine line = LineRoot.Global.Logger(Console.Out, LineStatusSeverity.Ok);
                #endregion Snippet_2b
            }
            {
                #region Snippet_2c
                ICulturePolicy culturePolicy = new CulturePolicy().SetToCurrentCulture();
                ILine          line          = LineRoot.Global.CulturePolicy(culturePolicy);
                #endregion Snippet_2c
            }
            {
                #region Snippet_2d
                #endregion Snippet_2d
            }
            {
                #region Snippet_2e
                #endregion Snippet_2e
            }
            {
                #region Snippet_2f
                #endregion Snippet_2f
            }
            {
                #region Snippet_2g
                #endregion Snippet_2g
            }
            {
                #region Snippet_2h
                #endregion Snippet_2h
            }

            // 3. Hints
            {
                #region Snippet_3_
                IAsset    asset = LineReaderMap.Default.FileAsset("ILine\\Hints.ini");
                ILineRoot root  = new LineRoot(asset);
                Console.WriteLine(root.Key("Error").Value(DateTime.Now));
                Console.WriteLine(root.Key("Ok"));
                #endregion Snippet_3_
            }
            {
                #region Snippet_3a
                ILine line1 = LineRoot.Global.StringFormat(TextFormat.Default).String("Text");
                ILine line2 = LineRoot.Global.StringFormat("Lexical.Localization.StringFormat.TextFormat,Lexical.Localization")
                              .String("Text");
                #endregion Snippet_3a
                Console.WriteLine(line2);
            }
            {
                #region Snippet_3b
                IPluralRules pluralRules = PluralRulesResolver.Default.Resolve("Unicode.CLDR35");
                ILine        line1       = LineRoot.Global.PluralRules(pluralRules);
                ILine        line2       = LineRoot.Global.PluralRules("Unicode.CLDR35");
                ILine        line3       = LineRoot.Global.PluralRules("[Category=cardinal,Case=one]n=1[Category=cardinal,Case=other]true");
                #endregion Snippet_3b
                Console.WriteLine(line2);
            }
            {
                #region Snippet_3c
                IFormatProvider customFormat = new CustomFormat();
                ILine           line1        = LineRoot.Global.FormatProvider(customFormat).Format("{0:DATE}").Value(DateTime.Now);
                ILine           line2        = LineRoot.Global.FormatProvider("docs.CustomFormat,docs").Format("{0:DATE}").Value(DateTime.Now);
                #endregion Snippet_3c
                Console.WriteLine(line1);
                Console.WriteLine(line2);
            }
            {
                #region Snippet_3e
                ResolveSource[] resolveSequence =
                    new ResolveSource[] { ResolveSource.Inline, ResolveSource.Asset, ResolveSource.Line };

                IStringResolver stringResolver = new StringResolver(Resolvers.Default, resolveSequence);
                ILine           line           = LineRoot.Global.StringResolver(stringResolver);
                #endregion Snippet_3e
                Console.WriteLine(line);
            }
            {
                #region Snippet_3f
                ILine line = LineRoot.Global.StringResolver("Lexical.Localization.StringFormat.StringResolver");
                #endregion Snippet_3f
                Console.WriteLine(line);
            }
            {
                #region Snippet_3g
                ResolveSource[] resolveSequence =
                    new ResolveSource[] { ResolveSource.Inline, ResolveSource.Asset, ResolveSource.Line };

                IResourceResolver resourceResolver = new ResourceResolver(Resolvers.Default, resolveSequence);
                ILine             line             = LineRoot.Global.ResourceResolver(resourceResolver);
                #endregion Snippet_3g
                Console.WriteLine(line);
            }
            {
                #region Snippet_3h
                ILine line = LineRoot.Global.ResourceResolver("Lexical.Localization.Resource.ResourceResolver");
                #endregion Snippet_3h
                Console.WriteLine(line);
            }

            // 4. Keys
            {
                #region Snippet_4a
                #endregion Snippet_4a
            }
            {
                #region Snippet_4b
                #endregion Snippet_4b
            }
            {
                #region Snippet_4c
                #endregion Snippet_4c
            }
            {
                #region Snippet_4d
                #endregion Snippet_4d
            }
            {
                #region Snippet_4e
                #endregion Snippet_4e
            }
            {
                #region Snippet_4f
                #endregion Snippet_4f
            }
            {
                #region Snippet_4g
                #endregion Snippet_4g
            }
            {
                #region Snippet_4h
                #endregion Snippet_4h
            }

            // 5. Non-canonicals
            {
                #region Snippet_5a
                Assembly asm   = typeof(ILine_Examples).Assembly;
                ILine    line1 = LineRoot.Global.Assembly(asm);
                ILine    line2 = LineRoot.Global.Assembly("docs");
                #endregion Snippet_5a
            }
            {
                #region Snippet_5b
                CultureInfo culture = CultureInfo.GetCultureInfo("en");
                ILine       line1   = LineRoot.Global.Culture(culture);
                ILine       line2   = LineRoot.Global.Culture("en");
                #endregion Snippet_5b
            }
            {
                #region Snippet_5c
                ILine line1 = LineRoot.Global.Type <ILine_Examples>();
                ILine line2 = LineRoot.Global.Type(typeof(ILine_Examples));
                #endregion Snippet_5c
            }
            {
                #region Snippet_5d
                #endregion Snippet_5d
            }
            {
                #region Snippet_5e
                #endregion Snippet_5e
            }
            {
                #region Snippet_5f
                #endregion Snippet_5f
            }
            {
                #region Snippet_5g
                #endregion Snippet_5g
            }
            {
                #region Snippet_5h
                #endregion Snippet_5h
            }

            // 6. Canonicals
            {
                #region Snippet_6a
                ILine line = LineRoot.Global.Key("Ok");
                #endregion Snippet_6a
            }
            {
                #region Snippet_6b
                ILine line = LineRoot.Global.Section("Resources").Key("Ok");
                #endregion Snippet_6b
            }
            {
                #region Snippet_6c
                ILine line = LineRoot.Global.Location(@"c:\dir");
                #endregion Snippet_6c
            }
            {
                #region Snippet_6d
                ILine line = LineRoot.Global.BaseName("docs.Resources");
                #endregion Snippet_6d
            }
            {
                #region Snippet_6e
                #endregion Snippet_6e
            }
            {
                #region Snippet_6f
                #endregion Snippet_6f
            }
            {
                #region Snippet_6g
                #endregion Snippet_6g
            }
            {
                #region Snippet_6h
                #endregion Snippet_6h
            }

            // 7. Strings
            {
                #region Snippet_7a
                IString str  = CSharpFormat.Default.Parse("ErrorCode = 0x{0:X8}");
                ILine   line = LineRoot.Global.Key("Error").String(str);
                #endregion Snippet_7a
            }
            {
                #region Snippet_7b
                ILine line = LineRoot.Global.Key("Error").StringFormat(CSharpFormat.Default).String("ErrorCode = 0x{0:X8}");
                #endregion Snippet_7b
            }
            {
                #region Snippet_7c
                ILine line = LineRoot.Global.Key("Error").Format("ErrorCode = 0x{0:X8}");
                #endregion Snippet_7c
            }
            {
                #region Snippet_7c2
                int   code = 0x100;
                ILine line = LineRoot.Global.Key("Error").Format($"ErrorCode = 0x{code:X8}");
                #endregion Snippet_7c2
                Console.WriteLine(line);
            }
            {
                #region Snippet_7d
                ILine line = LineRoot.Global.Key("Hello").Text("Hello World");
                #endregion Snippet_7d
            }
            {
                #region Snippet_7e
                ILine line = LineRoot.Global.Section("Section").Key("Success")
                             .Format("Success")                        // Add inlining to the root culture ""
                             .Inline("Culture:en", "Success")          // Add inlining to culture "en"
                             .Inline("Culture:fi", "Onnistui")         // Add inlining to culture "fi"
                             .Inline("Culture:sv", "Det funkar");      // Add inlining to culture "sv"
                #endregion Snippet_7e
            }
            {
                #region Snippet_7f
                ILine line = LineRoot.Global.Section("Section").Key("Success")
                             .Format("Success")                         // Add inlining to the root culture ""
                             .en("Success")                             // Add inlining to culture "en"
                             .fi("Onnistui")                            // Add inlining to culture "fi"
                             .sv("Det funkar");                         // Add inlining to culture "sv"
                #endregion Snippet_7f
            }

            // Enumerations
            {
                #region Snippet_7l
                ILine carFeature = LineRoot.Global.Assembly("docs").Type <CarFeature>().Format("{0}");
                #endregion Snippet_7l
            }
            {
                #region Snippet_7l2
                ILine carFeature = LineRoot.Global.Assembly("docs").Type <CarFeature>().InlineEnum <CarFeature>().Format("{0}");
                #endregion Snippet_7l2
            }
            {
                #region Snippet_7l3
                IAssetSource assetSource = LineReaderMap.Default.FileAssetSource(@"ILine\CarFeature.ini");
                LineRoot.Builder.AddSource(assetSource).Build();
                #endregion Snippet_7l3
            }
            {
                #region Snippet_7m
                ILine carFeature = LineRoot.Global.Assembly("docs").Type <CarFeature>()
                                   .InlineEnum <CarFeature>()
                                   .InlineEnum(CarFeature.Electric, "fi", "Sähkö")
                                   .InlineEnum(CarFeature.Petrol, "fi", "Bensiini")
                                   .InlineEnum(CarFeature.NaturalGas, "fi", "Maakaasu")
                                   .InlineEnum(CarFeature.TwoDoors, "fi", "Kaksiovinen")
                                   .InlineEnum(CarFeature.FourDoors, "fi", "Neliovinen")
                                   .InlineEnum(CarFeature.FiveDoors, "fi", "Viisiovinen")
                                   .InlineEnum(CarFeature.Red, "fi", "Punainen")
                                   .InlineEnum(CarFeature.Black, "fi", "Musta")
                                   .InlineEnum(CarFeature.White, "fi", "Valkoinen")
                                   .Format("{0}");
                #endregion Snippet_7m

                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("");
                #region Snippet_7m2
                Console.WriteLine(carFeature.Key(CarFeature.Petrol));
                Console.WriteLine(carFeature.Key(CarFeature.Petrol).Culture("fi"));
                Console.WriteLine(carFeature.Key(CarFeature.Petrol).Culture("sv"));
                #endregion Snippet_7m2

                #region Snippet_7m3
                CarFeature features = CarFeature.Petrol | CarFeature.FiveDoors | CarFeature.Black;
                Console.WriteLine(carFeature.Value(features));
                #endregion Snippet_7m3
                #region Snippet_7m5
                Console.WriteLine(carFeature.Formulate($"{CarFeature.Petrol | CarFeature.Black:|}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{CarFeature.Petrol | CarFeature.Black: |}").Culture("fi"));
                #endregion Snippet_7m5
            }
            {
                #region Snippet_7m6
                ILine carFeature = LineRoot.Global.Assembly("docs").Type <CarFeature>().InlineEnum <CarFeature>()
                                   .InlineEnum(CarFeature.Electric, "de", "Elektroauto")
                                   .InlineEnum(CarFeature.Petrol, "de", "Benzinwagen")
                                   .InlineEnum(CarFeature.NaturalGas, "de", "Erdgasauto")
                                   .InlineEnum(CarFeature.TwoDoors, "de", "Zweitürig")
                                   .InlineEnum(CarFeature.FourDoors, "de", "Viertürig")
                                   .InlineEnum(CarFeature.FiveDoors, "de", "Fünftürige")
                                   .InlineEnum(CarFeature.Red, "de", "Rot")
                                   .InlineEnum(CarFeature.Black, "de", "Schwartz")
                                   .InlineEnum(CarFeature.White, "de", "Weiß")
                                   .Format("{0}");

                ILine message = LineRoot.Global.Assembly("docs").Type("MyClass").Key("Msg")
                                .Format("Your car has following features: {0}")
                                .de("Ihr Auto hat folgende Eigenschaften: {0}");

                Console.WriteLine(message.Value(CarFeature.Petrol | CarFeature.Red | CarFeature.TwoDoors).Culture("fi"));
                Console.WriteLine(message.Value(CarFeature.Petrol | CarFeature.Red | CarFeature.TwoDoors).Culture("sv"));
                Console.WriteLine(message.Value(CarFeature.Petrol | CarFeature.Red | CarFeature.TwoDoors).Culture("de"));
                #endregion Snippet_7m6
            }
            {
                #region Snippet_7m7
                ILine carFeature = LineRoot.Global.Assembly("docs").Type <CarFeature>().InlineEnum <CarFeature>()
                                   .InlineEnum(CarFeature.Electric, "de", "Elektroauto")
                                   .InlineEnum(CarFeature.Petrol, "de", "Benzinwagen")
                                   .InlineEnum(CarFeature.NaturalGas, "de", "Erdgasauto")
                                   .InlineEnum(CarFeature.TwoDoors, "de", "Zweitürig")
                                   .InlineEnum(CarFeature.FourDoors, "de", "Viertürig")
                                   .InlineEnum(CarFeature.FiveDoors, "de", "Fünftürige")
                                   .InlineEnum(CarFeature.Red, "de", "Rot")
                                   .InlineEnum(CarFeature.Black, "de", "Schwartz")
                                   .InlineEnum(CarFeature.White, "de", "Weiß")
                                   .Format("{0}");

                ILine message = LineRoot.Global.Assembly("docs").Type("MyClass").Key("Msg")
                                .Format("Your car has following features: {0}")
                                .de("Ihr Auto hat folgende Eigenschaften: {0}");

                CarFeature features = CarFeature.Petrol | CarFeature.Red | CarFeature.TwoDoors;

                // Inlined enum strings don't work as Enum (unless tool is used)
                Console.WriteLine(message.Value(features).Culture("de"));
                // But works when ILine reference is used.
                Console.WriteLine(message.Value(carFeature.Value(features)).Culture("de"));
                #endregion Snippet_7m7
            }
            {
                ILine      carFeature = LineRoot.Global.Assembly("docs").Type <CarFeature>().InlineEnum <CarFeature>();
                CarFeature features   = CarFeature.Petrol | CarFeature.FiveDoors | CarFeature.Black;
                Console.WriteLine(carFeature.Formulate($"{features:g}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{features:G}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{features:f}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{features:F}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{features:d}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{features:D}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{features:x}").Culture("fi"));
                Console.WriteLine(carFeature.Formulate($"{features:X}").Culture("fi"));
            }

            // 8. Values
            {
                #region Snippet_8a
                ILine      line   = LineRoot.Global.Key("Error").Format("ErrorCode={0}").Value(0x100);
                LineString result = line.ResolveString();
                #endregion Snippet_8a
            }
            {
                #region Snippet_8b
                #endregion Snippet_8b
            }
            {
                #region Snippet_8c
                #endregion Snippet_8c
            }
            {
                #region Snippet_8d
                #endregion Snippet_8d
            }
            {
                #region Snippet_8e
                #endregion Snippet_8e
            }
            {
                #region Snippet_8f
                #endregion Snippet_8f
            }
            {
                #region Snippet_8g
                #endregion Snippet_8g
            }
            {
                #region Snippet_8h
                #endregion Snippet_8h
            }

            // 10. Resources
            {
                #region Snippet_10a
                ILine             line   = LineRoot.Global.Key("Error").Resource(new byte[] { 1, 2, 3 });
                LineResourceBytes result = line.ResolveBytes();
                #endregion Snippet_10a
            }
            {
                #region Snippet_10b
                ILine line = LineRoot.Global.Key("Error").Resource(new byte[] { 1, 2, 3 });
                using (LineResourceStream result = line.ResolveStream())
                {
                }
                #endregion Snippet_10b
            }
            {
                #region Snippet_10c
                #endregion Snippet_10c
            }
            {
                #region Snippet_10d
                #endregion Snippet_10d
            }
            {
                #region Snippet_10e
                #endregion Snippet_10e
            }
            {
                #region Snippet_10f
                #endregion Snippet_10f
            }
            {
                #region Snippet_10g
                #endregion Snippet_10g
            }
            {
                #region Snippet_10h
                #endregion Snippet_10h
            }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            {
                #region Snippet_1a
                ILine line = LineRoot.Global.Type("MyClass").Key("hello").Format("Hello, {0}.");
                #endregion Snippet_1a
                #region Snippet_1b
                Console.WriteLine(line.Value("Corellia Melody"));
                #endregion Snippet_1b
                #region Snippet_1c
                Console.WriteLine(LineRoot.Global.Format("It is now {0:d} at {0:t}").Value(DateTime.Now));
                Console.WriteLine(String.Format("It is now {0:d} at {0:t}", DateTime.Now));
                #endregion Snippet_1c
                #region Snippet_1c1
                DateTime time = DateTime.Now;
                Console.WriteLine(LineRoot.Global.Key("Time").Formulate($"It is now {time:d} at {time:t}"));
                #endregion Snippet_1c1
                #region Snippet_1c2
                Console.WriteLine(LineRoot.Global.Format("It is now {0:d} at {0:t}").Culture("sv").Value(DateTime.Now));
                Console.WriteLine(LineRoot.Global.Format("It is now {0:d} at {0:t}").Culture("de").Value(DateTime.Now));
                #endregion Snippet_1c2
                #region Snippet_1d
                LineString resolved_string = line.Value("Corellia Melody").ResolveString();
                Console.WriteLine(resolved_string.Status);
                #endregion Snippet_1d
                #region Snippet_1e
                Permissions permissions = Permissions.Add | Permissions.Modify | Permissions.Remove;
                Console.WriteLine(LineRoot.Global.Key("Permission").Formulate($"User permissions {permissions}"));
                #endregion Snippet_1e
            }
            {
                #region Snippet_2
                ILine line = LineRoot.Global
                             .Key("hello")
                             .Format("Hello, {0}.")
                             .Inline("Culture:fi", "Hei, {0}")
                             .Inline("Culture:de", "Hallo, {0}");
                Console.WriteLine(line.Value("Corellia Melody"));
                #endregion Snippet_2
            }
            {
                #region Snippet_3
                ILine line = LineRoot.Global.PluralRules("Unicode.CLDR35")
                             .Type("MyClass").Key("Cats")
                             .Format("{cardinal:0} cat(s)")
                             .Inline("N:zero", "no cats")
                             .Inline("N:one", "a cat")
                             .Inline("N:other", "{0} cats");
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Value(cats));
                }
                #endregion Snippet_3
            }
            {
                #region Snippet_4
                ILine line = LineRoot.Global.PluralRules("Unicode.CLDR35")
                             .Type("MyClass").Key("Cats")
                             .Format("{0} cat(s)")
                             .Inline("Culture:en", "{cardinal:0} cat(s)")
                             .Inline("Culture:en:N:zero", "no cats")
                             .Inline("Culture:en:N:one", "a cat")
                             .Inline("Culture:en:N:other", "{0} cats")
                             .Inline("Culture:fi", "{cardinal:0} kissa(a)")
                             .Inline("Culture:fi:N:zero", "ei kissoja")
                             .Inline("Culture:fi:N:one", "yksi kissa")
                             .Inline("Culture:fi:N:other", "{0} kissaa");

                // Print with plurality and to culture "en"
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Culture("en").Value(cats));
                }
                #endregion Snippet_4
            }
            {
                #region Snippet_5a
                IAsset asset = LineReaderMap.Default.FileAsset("PluralityExample0a.xml");
                LineRoot.Builder.AddAsset(asset).Build();
                ILine line = LineRoot.Global.Key("Cats").Format("{0} cat(s)");
                // Print with plurality
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Culture("fi").Value(cats));
                }
                #endregion Snippet_5a
            }
            {
                #region Snippet_5b
                IAsset    asset = LineReaderMap.Default.FileAsset("PluralityExample0a.xml");
                ILineRoot root  = new LineRoot(asset, new CulturePolicy());
                ILine     line  = root.Key("Cats").Format("{0} cat(s)");
                #endregion Snippet_5b
                // Print with plurality
                for (int cats = 0; cats <= 2; cats++)
                {
                    Console.WriteLine(line.Culture("fi").Value(cats));
                }
            }
            {
                #region Snippet_6
                List <ILine> lines = new List <ILine> {
                    LineAppender.Default.Type("MyClass").Key("Hello").Format("Hello, {0}"),
                    LineAppender.Default.Type("MyClass").Key("Hello").Culture("fi").Format("Hei, {0}"),
                    LineAppender.Default.Type("MyClass").Key("Hello").Culture("de").Format("Hallo, {0}")
                };
                IAsset    asset = new StringAsset().Add(lines).Load();
                ILineRoot root  = new LineRoot(asset, new CulturePolicy());
                ILine     line  = root.Type("MyClass").Key("Hello");
                Console.WriteLine(line.Value("Corellia Melody"));
                #endregion Snippet_6
            }
            {
                #region Snippet_7
                ILine root = LineRoot.Global.Logger(Console.Out, LineStatusSeverity.Ok);
                ILine line = root.Type("MyClass").Key("hello").Format("Hello, {0}.");
                Console.WriteLine(line.Value("Corellia Melody"));
                #endregion Snippet_7
            }
            {
                #region Snippet_8
                ILine   line1a  = LineRoot.Global.Key("Cats").Format("{0} cat(s)");
                IString string1 = CSharpFormat.Default.Parse("{0} cat(s)");
                ILine   line1b  = LineRoot.Global.Key("Cats").String(string1);

                ILine   line2a  = LineRoot.Global.Key("Ok").Text("{in braces}");
                IString string2 = TextFormat.Default.Parse("{in braces}");
                ILine   line2b  = LineRoot.Global.Key("Ok").String(string2);
                #endregion Snippet_8
            }
            {
                #region Snippet_9
                ICulturePolicy culturePolicy = new CulturePolicy().SetToCurrentThreadUICulture();
                ILine          root          = new LineRoot(null, culturePolicy: culturePolicy);
                #endregion Snippet_9
            }
            {
                #region Snippet_10
                ILine                   line             = StringLocalizerRoot.Global.Type("MyClass").Key("hello").Format("Hello, {0}.");
                IStringLocalizer        localizer        = line.AsStringLocalizer();
                IStringLocalizerFactory localizerFactory = line.AsStringLocalizerFactory();
                #endregion Snippet_10
            }
            {
                #region Snippet_11
                ILineRoot               root             = new StringLocalizerRoot(null, new CulturePolicy());
                ILine                   line             = root.Type("MyClass").Key("hello").Format("Hello, {0}.");
                IStringLocalizer        localizer        = line.AsStringLocalizer();
                IStringLocalizerFactory localizerFactory = line.AsStringLocalizerFactory();
                #endregion Snippet_11
            }
            {
                #region Snippet_12
                ILine                   line             = LineRoot.Global.Type("MyClass").Key("hello").Format("Hello, {0}.");
                IStringLocalizer        localizer        = line.AsStringLocalizer();
                IStringLocalizerFactory localizerFactory = line.AsStringLocalizerFactory();
                #endregion Snippet_12
            }
            {
                #region Snippet_13
                #endregion Snippet_13
            }
            {
                #region Snippet_14
                #endregion Snippet_14
            }
            {
                #region Snippet_15
                #endregion Snippet_15
            }
        }