/// /// Retrieves a discount strategy associated to the customer type /// ///Based on the type of customer, return the appropriate discount strategy /// the appropriate discount strategy public static IDiscountStrategy GetDiscountStrategyForCustomerType(StrategyPattern.Enumerations.EventEnumerations.CustomerType customerType) { //Retrieve the enumeration's attributes specified in Enumerations/EventEnumerations.cs FieldInfo field = customerType.GetType().GetField(customerType.ToString()); object[] attribs = field.GetCustomAttributes(typeof(DiscountTypeAttribute), false); //If no attribute was specified, then return the normal price by default if (attribs.Length == 0) return new NullDiscountStrategy(); return Activator.CreateInstance((attribs[0] as DiscountTypeAttribute).DiscountStrategy) as IDiscountStrategy; } }