/// <summary> /// Adds a class for code generation or CG plugin. /// /// Checks if the class implements G25.CodeGenerator. If so, creates an instance, /// checks if it supports the required Language, and if so, keeps the instance in m_codeGenerator. /// /// Also checks if the class implements G25.CodeGeneratorPlugin. If so, creates an instance, /// checks if it supports the required Language, and if so, keeps the instance in m_codeGeneratorPlugins. /// </summary> /// <param name="T">Any type (if the type does not support the CG interrface(s), nothing happens)</param> public void AddClass(Type T) { if (typeof(G25.CodeGenerator).IsAssignableFrom(T)) { try { G25.CodeGenerator CG = System.Activator.CreateInstance(T) as G25.CodeGenerator; if ((CG != null) && (CG.Language().ToLower() == Language)) { SetMainCodeGenerator(CG); } } catch (System.Exception) { } } if (typeof(G25.CodeGeneratorPlugin).IsAssignableFrom(T)) { try { G25.CodeGeneratorPlugin P = System.Activator.CreateInstance(T) as G25.CodeGeneratorPlugin; if ((P != null) && (P.Language().ToLower() == Language)) { AddCodeGeneratorPlugin(P); } } catch (System.Exception) { } } }
/// <summary> /// Sets the main code generator to 'CG'. If CG does not support the right language, throws an exception. /// </summary> public void SetMainCodeGenerator(G25.CodeGenerator CG) { if (CG.Language() != Language) { throw new Exception("G25.CodeGeneratorLoader.SetMainCodeGenerator(): the code generator does not generate for language '" + Language + "' but for language '" + CG.Language() + "' instead"); } if (m_codeGenerator != null) { if (m_codeGenerator.GetType() == CG.GetType()) { return; } // else: TO DO; // a duplicate of the code generator was detected. Now what? throw an exception? write an error message to console? TO DO! } m_codeGenerator = CG; }