public Knapsack SolveProblemUsing( KnapsackAlgorithmType algorithmType, List <Supply> possibleSupplies, int maxWeight) { // loop thru all registered implementations foreach (Type impl in RegisteredImplementations) { // get attributes for this type object[] attrlist = impl.GetCustomAttributes(true); // loop thru all attributes for this class foreach (object attr in attrlist) { if (attr is KnapsackAlgorithmAttribute) { if (((KnapsackAlgorithmAttribute)attr).TypeOfAlgorithm.Equals(algorithmType)) { IKnapsackAlgorithm knapsackAlgorithm = (KnapsackAlgorithmBase)Activator.CreateInstance(impl); return(knapsackAlgorithm.Execute(possibleSupplies, maxWeight)); } } } } throw new Exception("Could not find a KnapsackAlgorithmBase implementation for this AlgorithmType"); }
public KnapsackAlgorithmAttribute(KnapsackAlgorithmType algorithmType) { this.algorithmType = algorithmType; }