/// <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> /// Adds 'P' to the list of code generator plugins'. /// If P does not support the right language, throws an exception. /// Does nothing if 'P' is already on the list. /// </summary> public void AddCodeGeneratorPlugin(G25.CodeGeneratorPlugin P) { if (P.Language() != Language) { throw new Exception("G25.CodeGeneratorLoader.AddCodeGeneratorPlugin(): the code generator does not generate for language '" + Language + "' but for language '" + P.Language() + "' instead"); } // if already on list simply return for (int i = 0; i < m_codeGeneratorPlugins.Count; i++) { if (m_codeGeneratorPlugins[i].GetType() == P.GetType()) { return; } } m_codeGeneratorPlugins.Add(P); }