/// <summary>
        /// A listing of available replacement tokens, with their values for the date provided
        /// </summary>
        public IEnumerable <string> AvailableTokens(BadiDate testDate = null, string template = null)
        {
            testDate = testDate ?? new BadiDate();
            template = template ?? "<dt>{{{0}}}</dt><dd>{1}</dd>";

            var dict = AvailableReplacements(testDate);
            var keys = dict.Keys;

            // test each for compound keys
            foreach (var key in keys)
            {
                var value = dict[key].GetValue(key);

                if (value.GetType().IsGenericType)
                {
                    foreach (var minorKey in ((Dictionary <string, CompiledExpression>)value).Keys)
                    {
                        string compoundKey = $"{key}.{minorKey}";
                        yield return(String.Format(template, compoundKey, testDate.ToString($"{{{compoundKey}}}")));
                    }
                }
                else
                {
                    yield return(String.Format(template, key, testDate.ToString($"{{{key}}}")));
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Today is {new BadiDate().ToString()}");

            var d1 = LocalDate.FromDateTime(DateTime.Now);

            Console.WriteLine($"Today is {d1.ToString()}");
            var w1 = new BadiDate(d1);

            Console.WriteLine($"Today is {w1.ToString()}");

            var w2 = new BadiDate();
            var d2 = w2.DateTime;

            Console.WriteLine($"{w2} --> {d2}");

            var date3          = new BadiDate(175, 1, 1);
            var gregorianDate2 = date3.PlusDays(-1).DateTime;

            Console.WriteLine("The day before Naw Rúz 175 is " + gregorianDate2.ToString("D"));

            var year174 = new BadiYearInfo(174);
            var listing = year174.GetSpecialDays(SpecialDayType.HolyDay_WorkSuspended | SpecialDayType.FeastDay);

            Console.WriteLine($"There are {listing.Count} Feast and major Holy Days in 174.");

            var nawRuz = year174.GetSpecialDays(SpecialDayType.HolyDay_WorkSuspended, HolyDayCode.NawRuz).First();

            Console.WriteLine($"Naw Ruz was on {nawRuz.Date.ToString()}");


            var dtp = new BadiNodaTime.Utility.DateTemplateProcessor();

            dtp.AvailableTokens(w2).ToList().ForEach(Console.WriteLine);

            Console.WriteLine("\nGerman...");
            var resolver = new BadiResources("de");

            dtp = new BadiNodaTime.Utility.DateTemplateProcessor(resolver);
            dtp.AvailableTokens(w2).ToList().ForEach(Console.WriteLine);
        }