public override void Execute() { if (CreateTask == null) { CreateTask = new CreateTask(); } var listOfInjected = new List <string>(); PropertyInfo[] properties = TaskContainingSubTasks.GetType().GetProperties(); foreach (PropertyInfo propertyX in properties) { if (propertyX.PropertyType.IsSubclassOf(typeof(Task))) { if (propertyX.CanWrite && propertyX.GetValue(TaskContainingSubTasks, null) == null) { CreateTask.TaskType = propertyX.PropertyType; CreateTask.Execute(); propertyX.SetValue(TaskContainingSubTasks, CreateTask.TaskInstance, null); listOfInjected.Add(propertyX.PropertyType.FullName); } } } InjectedSubTaskPropertyNames = listOfInjected.ToArray(); }
public override void Execute() { var listOfInjected = new List <string>(InjectedSubTaskPropertyNames); PropertyInfo[] properties = TaskContainingSubTasks.GetType().GetProperties(); foreach (PropertyInfo propertyX in properties) { if (propertyX.PropertyType.IsSubclassOf(typeof(Task))) { if (listOfInjected.Contains(propertyX.PropertyType.FullName) && propertyX.GetValue(TaskContainingSubTasks, null) != null && (propertyX.PropertyType.GetInterface(typeof(IDisposable).FullName) != null)) { // Dispose the sub-task. ((IDisposable)propertyX.GetValue(TaskContainingSubTasks, null)).Dispose(); // Set the sub-task to null. propertyX.SetValue(TaskContainingSubTasks, null, null); } } } }