Пример #1
0
        /// <summary>
        /// Combine combines a child with a parent as necessary and returns the combined object
        /// </summary>
        /// <param name="combinedCalendarNameSet">The child object</param>
        /// <param name="parentCalendarNameSet">The parent object</param>
        /// <returns>The combined object</returns>
        public static CalendarNameSet <T> Combine(
            CalendarNameSet <T> combinedCalendarNameSet,
            CalendarNameSet <T> parentCalendarNameSet)
        {
            if (combinedCalendarNameSet == null && parentCalendarNameSet == null)
            {
                return(null);
            }
            else if (combinedCalendarNameSet == null)
            {
                return((CalendarNameSet <T>)parentCalendarNameSet.Clone());
            }
            else if (parentCalendarNameSet == null)
            {
                return(combinedCalendarNameSet);
            }

            List <T> combinedCalendarNames = new List <T>(combinedCalendarNameSet.Names);

            foreach (T parentCalendarName in parentCalendarNameSet.Names)
            {
                if (!(from cn in combinedCalendarNames
                      where string.Compare(cn.Id, parentCalendarName.Id, StringComparison.InvariantCultureIgnoreCase) == 0
                      select cn).Any())
                {
                    // the parent name is not in the combined list
                    combinedCalendarNames.Add(parentCalendarName);
                }
            }

            combinedCalendarNameSet.Names = combinedCalendarNames.ToArray();
            return(combinedCalendarNameSet);
        }
Пример #2
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());
        }
Пример #3
0
        /// <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);
        }