- Timestamp:
- 02/04/15 13:28:37 (9 years ago)
- Location:
- branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/ProblemDefinitionScript.cs
r11880 r11885 71 71 var assembly = base.Compile(); 72 72 var types = assembly.GetTypes(); 73 if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))) 74 throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition."); 75 if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1) 76 throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed."); 77 78 CompiledProblemDefinition inst; 73 79 try { 74 var inst = (CompiledProblemDefinition)Activator.CreateInstance(types.First(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))); 80 inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))); 81 } catch (Exception e) { 82 compiledProblemDefinition = null; 83 throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e); 84 } 85 86 try { 75 87 inst.vars = new Variables(VariableStore); 76 88 inst.Initialize(); 89 } catch (Exception e) { 90 compiledProblemDefinition = null; 91 throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e); 92 } 93 94 try { 77 95 CompiledProblemDefinition = inst; 78 96 } catch (Exception e) { 79 97 compiledProblemDefinition = null; 80 throw ;98 throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e); 81 99 } 100 82 101 return assembly; 83 102 }
Note: See TracChangeset
for help on using the changeset viewer.