private static void Generate(string xamlFile, string outputFile, RenderMode renderMode) { string xaml = string.Empty; using (TextReader tr = File.OpenText(xamlFile)) { xaml = tr.ReadToEnd(); } UserInterfaceGenerator generator = new UserInterfaceGenerator(); string generatedCode = generator.GenerateCode(xamlFile, xaml, renderMode); using (StreamWriter outfile = new StreamWriter(outputFile)) { outfile.Write(generatedCode); } }
private static void Generate(string xamlFile, string outputFile, RenderMode renderMode, string desiredNamespace, string defaultAssembly, string header) { string xaml = string.Empty; using (TextReader tr = File.OpenText(xamlFile)) { xaml = tr.ReadToEnd(); } if (!string.IsNullOrEmpty(defaultAssembly)) { xaml = Regex.Replace(xaml, @"xmlns(:\w+)?=\""clr-namespace:([.\w]+)(;assembly=)?\""", $@"xmlns$1=""clr-namespace:$2;assembly=" + defaultAssembly + '"'); } UserInterfaceGenerator generator = new UserInterfaceGenerator(); string generatedCode = string.Empty; try { generatedCode = generator.GenerateCode(xamlFile, xaml, renderMode, desiredNamespace, header); } catch (Exception ex) { generatedCode = "#error " + ex.Message; throw; } finally { string directory = Path.GetDirectoryName(outputFile); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (StreamWriter outfile = new StreamWriter(outputFile)) { outfile.Write(generatedCode); } } }