예제 #1
0
        /// <summary>
        /// Combine combines a child with a parent as necessary and returns the combined object
        /// </summary>
        /// <param name="combinedCalendarNameSets">The child object</param>
        /// <param name="parentCalendarNameSets">The parent object</param>
        /// <returns>The combined object</returns>
        public static W[] Combine <W>(
            W[] combinedCalendarNameSets,
            W[] parentCalendarNameSets) where W : CalendarNameSet <T>
        {
            if ((combinedCalendarNameSets == null || combinedCalendarNameSets.GetLength(0) == 0) &&
                (parentCalendarNameSets == null || parentCalendarNameSets.GetLength(0) == 0))
            {
                return(null);
            }
            else if (combinedCalendarNameSets == null || combinedCalendarNameSets.GetLength(0) == 0)
            {
                return((W[])parentCalendarNameSets.Clone());
            }
            else if (parentCalendarNameSets == null || parentCalendarNameSets.GetLength(0) == 0)
            {
                return(combinedCalendarNameSets);
            }

            List <W> combinedCalendarNameSetList = new List <W>(combinedCalendarNameSets);

            foreach (W parentCalendarNameSet in parentCalendarNameSets)
            {
                CalendarNameSet <T> combinedCalendarNameSet = (from ups in combinedCalendarNameSets
                                                               where string.Compare(ups.Id, parentCalendarNameSet.Id, StringComparison.InvariantCulture) == 0 &&
                                                               string.Compare(ups.Context, parentCalendarNameSet.Context, StringComparison.InvariantCulture) == 0
                                                               select ups).FirstOrDefault();
                if (combinedCalendarNameSet == null)
                {
                    // this name set does not exist in the combined list
                    combinedCalendarNameSetList.Add(parentCalendarNameSet);
                }
                else
                {
                    // combine the items of the two sets
                    combinedCalendarNameSet = CalendarNameSet <T> .Combine(combinedCalendarNameSet, parentCalendarNameSet);
                }
            }

            return(combinedCalendarNameSetList.ToArray());
        }
예제 #2
0
파일: Calendar.cs 프로젝트: pifta/NCLDR
        /// <summary>
        /// Combine combines a child with a parent as necessary and returns the combined object
        /// </summary>
        /// <param name="combinedCalendar">The child object</param>
        /// <param name="parentCalendar">The parent object</param>
        /// <returns>The combined object</returns>
        public static Calendar Combine(Calendar combinedCalendar, Calendar parentCalendar)
        {
            if (combinedCalendar.DateFormats == null || combinedCalendar.DateFormats.GetLength(0) == 0)
            {
                combinedCalendar.DateFormats = parentCalendar.DateFormats;
            }

            combinedCalendar.DayNameSets = CalendarNameSet <DayName> .Combine <DayNameSet>(
                combinedCalendar.DayNameSets,
                parentCalendar.DayNameSets);

            if (combinedCalendar.DayPeriodNameSets == null || combinedCalendar.DayPeriodNameSets.GetLength(0) == 0)
            {
                combinedCalendar.DayPeriodNameSets = parentCalendar.DayPeriodNameSets;
            }

            if (combinedCalendar.EraNameSets == null || combinedCalendar.EraNameSets.GetLength(0) == 0)
            {
                combinedCalendar.EraNameSets = parentCalendar.EraNameSets;
            }

            if (combinedCalendar.MonthNameSets == null || combinedCalendar.MonthNameSets.GetLength(0) == 0)
            {
                combinedCalendar.MonthNameSets = parentCalendar.MonthNameSets;
            }
            else
            {
                combinedCalendar.MonthNameSets =
                    CombineMonthNameSets(combinedCalendar.MonthNameSets, parentCalendar.MonthNameSets);
            }

            if (combinedCalendar.TimeFormats == null || combinedCalendar.TimeFormats.GetLength(0) == 0)
            {
                combinedCalendar.TimeFormats = parentCalendar.TimeFormats;
            }

            return(combinedCalendar);
        }