private static void AddTasksToRecipe(Type type, Recipe recipe)
{
//loop through methods in class
foreach(var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly ))
{
//get the custom attributes on the method
var foundAttributes = method.GetCustomAttributes(typeof(TaskAttribute), false);
if(foundAttributes.Length > 1)
throw new Exception("Should only be one task attribute on a method");
//if none, skp to the next method
if (foundAttributes.Length == 0)
continue;
var taskAttribute = foundAttributes[0] as TaskAttribute;
if (taskAttribute == null)
throw new Exception("couldn't cast TaskAttribute correctly, more that one assembly loaded?");
//get the task based on attribute contents
Task t = CreateTaskFromAttribute(method, taskAttribute);
//build list of dependent tasks
CreateDependentTasks(type, taskAttribute, t);
//add the task to the recipe
recipe.Tasks.Add(t);
}
}