Ejemplo n.º 1
0
        /// <summary>Gets the holiday calendar from a specific enumeration, where the elements of the enumeration has to
        /// have some <see cref="HolidayAttribute"/> attribute containing the holiday information and the enumeration
        /// has to have a <see cref="CustomHolidayCalendarAttribute"/>.
        /// </summary>
        /// <param name="enumType">The <see cref="System.Type"/> of the enumeration where each element
        /// contains some <see cref="HolidayAttribute"/> attribute.</param>
        /// <returns>A holiday calendar with respect to <paramref name="enumType"/>.</returns>
        /// <exception cref="ArgumentException">Thrown if <paramref name="enumType"/> does not represent an enumeration or no attributes are given.</exception>
        public static IHolidayCalendar Create(Type enumType)
        {
            if ((enumType == null) || (!enumType.IsEnum))
            {
                throw new ArgumentException("Enumeration types allowed only.", "enumType");
            }
            CustomHolidayCalendarAttribute enumTypeAttribute = EnumAttribute.Create <CustomHolidayCalendarAttribute>(enumType);

            if ((enumTypeAttribute == null) || (enumTypeAttribute.FullResourceName == null) || (enumTypeAttribute.FullResourceName.Length == 0))
            {
                throw new InvalidOperationException("The enumeration type '" + enumType.Name + "' does not contains the 'CustomHolidayCalendarAttribute' with a valid resource name.");
            }
            /* now get the list of holidays with respect to the holiday calendar: */
            List <IHoliday> holidayList     = new List <IHoliday>();
            ResourceManager resourceManager = new ResourceManager(enumTypeAttribute.FullResourceName, enumType.Assembly);

            foreach (Enum holiday in Enum.GetValues(enumType))
            {
                HolidayAttribute holidayAttribute = EnumAttribute.Create <HolidayAttribute>(holiday);
                if (holidayAttribute != null)
                {
                    holidayList.Add(holidayAttribute.GetHoliday(resourceManager));
                }
            }
            IdentifierString calendarName = new IdentifierString(enumTypeAttribute.CalendarName);

            /* try to get some (language depending) description of the holiday calendar: */
            string description = null;

            if ((enumTypeAttribute.Description != null) && (String.IsNullOrEmpty(enumTypeAttribute.Description) == false))
            {
                description = resourceManager.GetString(enumTypeAttribute.Description, Thread.CurrentThread.CurrentUICulture);
            }
            return(new CustomHolidayCalendar(calendarName, enumTypeAttribute.Region, holidayList, enumTypeAttribute.FirstDate, enumTypeAttribute.LastDate, description));
        }
Ejemplo n.º 2
0
        /// <summary>Creates the specified <see cref="NLoptConfiguration"/>.
        /// </summary>
        /// <param name="nloptAlgorithm">The NLopt algorithm in its <see cref="NLoptAlgorithm"/> representation.</param>
        /// <returns>The configuration of the specified NLopt algorithm in its <see cref="NLoptConfiguration"/> representation.</returns>
        public static NLoptConfiguration Create(NLoptAlgorithm nloptAlgorithm)
        {
            var attribute = EnumAttribute.Create <NLoptAlgorithmAttribute>(nloptAlgorithm);

            return(attribute.GetConfiguration());
        }