private static string BuildParserClass(string dllName, string path, SharpClass sharpClass) { var sc = new SourceCompiler(dllName, path); sc.UseAppdomain = true; sc.AddFile(sharpClass); sc.LoadCurrentAssemblies(); var loadedAssembly = sc.Compile(); Assert.IsNotNull(loadedAssembly); Assert.IsFalse(sc.HasErrors); return loadedAssembly; }
/// <summary> /// Iterate the block and setup the SharpClass content /// </summary> /// <param name="elaborated"></param> /// <param name="className"></param> /// <param name="nameSpace"></param> /// <returns></returns> private SharpClass GenerateClass(IEnumerable<ParserBlock> elaborated, string className, string nameSpace) { var sharpClass = new SharpClass { ClassName = className, ClassNamespace = nameSpace }; foreach (var block in elaborated) { switch (block.Blocktype) { case (ParserBlockType.Base): if (!string.IsNullOrWhiteSpace(sharpClass.Base)) throw new Exception("Duplicate Base Tag"); sharpClass.Base = block.Content; break; case (ParserBlockType.Code): sharpClass.Content += block.Content; break; case (ParserBlockType.Direct): sharpClass.Content += block.Content; break; case (ParserBlockType.Model): if (!string.IsNullOrWhiteSpace(sharpClass.Model)) throw new Exception("Duplicate Model Tag"); sharpClass.Model = block.Content; break; case (ParserBlockType.Using): sharpClass.Using.Add(block.Content); break; } } if (string.IsNullOrWhiteSpace(sharpClass.Model)) { sharpClass.Model = "object"; } return sharpClass; }
/// <summary> /// Add a parsed Sharp file /// </summary> /// <param name="classDefinition"></param> /// <param name="reference"></param> /// <returns></returns> public string AddFile(SharpClass classDefinition, object reference = null) { return AddFile(classDefinition.ClassNamespace, classDefinition.ClassName, classDefinition.ToString(), reference); }