public CodeGenerationResult GenerateProjectCode(string file, string namespaceName, CodeDomProvider provider, GenerationOptions options, params Project[] projects) { ArrayList files = new ArrayList(); CodeGenerationResult res = GenerateProjectCode(options, projects); ICodeGenerator gen = provider.CreateGenerator(); string basePath = Path.GetDirectoryName(file); string ext = Path.GetExtension(file); foreach (SteticCompilationUnit unit in res.Units) { string fname; if (unit.Name.Length == 0) { fname = file; } else { fname = Path.Combine(basePath, unit.Name) + ext; } files.Add(fname); unit.Name = fname; StreamWriter fileStream = new StreamWriter(fname); try { gen.GenerateCodeFromCompileUnit(unit, fileStream, new CodeGeneratorOptions()); } finally { fileStream.Close(); } } return(res); }
static int GenerateCode(string file, string[] args, int n, GenerationOptions ops) { foreach (string lib in libraries) { SteticApp.AddWidgetLibrary(lib); } SteticApp.UpdateWidgetLibraries(false); Project[] projects = new Project [args.Length - n]; for (int i = n; i < args.Length; i++) { projects [i - n] = SteticApp.LoadProject(args [i]); } CodeDomProvider provider = GetProvider(language); CodeGenerationResult res = SteticApp.GenerateProjectCode(file, "Stetic", provider, ops, projects); foreach (SteticCompilationUnit f in res.Units) { Console.WriteLine("Generated file: " + f.Name); } foreach (string s in res.Warnings) { Console.WriteLine("WARNING: " + s); } return(0); }
public static void GenerateProjectCode(string file, CodeDomProvider provider, GenerationOptions options, ProjectBackend[] projects) { CodeGenerationResult res = GenerateProjectCode(options, projects); ICodeGenerator gen = provider.CreateGenerator(); string basePath = Path.GetDirectoryName(file); foreach (SteticCompilationUnit unit in res.Units) { string fname; if (unit.Name.Length == 0) { fname = file; } else { fname = Path.Combine(basePath, unit.Name); } StreamWriter fileStream = new StreamWriter(fname); try { gen.GenerateCodeFromCompileUnit(unit, fileStream, new CodeGeneratorOptions()); } finally { fileStream.Close(); } } }
public CodeGenerationResult GenerateProjectCode(string file, string namespaceName, CodeDomProvider provider, GenerationOptions options, params Project[] projects) { ArrayList files = new ArrayList(); CodeGenerationResult res = GenerateProjectCode(options, projects); string basePath = Path.GetDirectoryName(file); string ext = Path.GetExtension(file); foreach (SteticCompilationUnit unit in res.Units) { string fname; if (unit.Name.Length == 0) { if (provider is Microsoft.CSharp.CSharpCodeProvider && unit.Namespaces.Count > 0) { var types = unit.Namespaces [0].Types; if (types.Count > 0) { types [0].Members.Insert(0, new CodeSnippetTypeMember("#pragma warning disable 436")); } } fname = file; } else { fname = Path.Combine(basePath, unit.Name) + ext; } files.Add(fname); unit.Name = fname; StreamWriter fileStream = new StreamWriter(fname); try { provider.GenerateCodeFromCompileUnit(unit, fileStream, new CodeGeneratorOptions()); } finally { fileStream.Close(); } } return(res); }