// This creates a wrapper class for the config script that contains static methods for constructing modules internal string GenerateScript(string declarations, string script, HashSet <Type> moduleTypes, HashSet <string> namespaces) { // Start the script, adding all requested namespaces StringBuilder scriptBuilder = new StringBuilder(); scriptBuilder.AppendLine(string.Join(Environment.NewLine, namespaces.Select(x => "using " + x + ";"))); if (declarations != null) { scriptBuilder.AppendLine(declarations); } scriptBuilder.Append(@" public static class ConfigScript { public static void Run(IDictionary<string, object> Metadata, IPipelineCollection Pipelines, string RootFolder, string InputFolder, string OutputFolder) {" + Environment.NewLine + script + @" }"); // Add static methods to construct each module // Use Roslyn to get a display string for each constructor foreach (Type moduleType in moduleTypes) { scriptBuilder.Append(GenerateModuleConstructorMethods(moduleType)); } scriptBuilder.Append("}"); // Need to replace all instances of module type method name shortcuts to make them fully-qualified SyntaxTree scriptTree = CSharpSyntaxTree.ParseText(scriptBuilder.ToString()); ConfigRewriter configRewriter = new ConfigRewriter(moduleTypes); script = configRewriter.Visit(scriptTree.GetRoot()).ToFullString(); return(script); }
public static string Generate(string declarations, string config, HashSet <Type> moduleTypes, IEnumerable <string> namespaces) { // Start the script, adding all requested namespaces StringBuilder scriptBuilder = new StringBuilder(); scriptBuilder.AppendLine(string.Join(Environment.NewLine, namespaces.Select(x => "using " + x + ";"))); if (!string.IsNullOrWhiteSpace(declarations)) { scriptBuilder.AppendLine(declarations); } scriptBuilder.Append(@" public class ConfigScript : ConfigScriptBase { public ConfigScript(IEngine engine) : base(engine) { } public override void Run() {" + Environment.NewLine + config + @" }"); // Add static methods to construct each module Dictionary <string, string> moduleNames = new Dictionary <string, string>(); foreach (Type moduleType in moduleTypes) { scriptBuilder.Append(GenerateModuleConstructorMethods(moduleType, moduleNames)); } scriptBuilder.Append("}"); // Need to replace all instances of module type method name shortcuts to make them fully-qualified SyntaxTree scriptTree = CSharpSyntaxTree.ParseText(scriptBuilder.ToString()); ConfigRewriter configRewriter = new ConfigRewriter(moduleTypes); return(configRewriter.Visit(scriptTree.GetRoot()).ToFullString()); }
// This creates a wrapper class for the config script that contains static methods for constructing modules internal string GenerateScript(string declarations, string script, HashSet<Type> moduleTypes, HashSet<string> namespaces) { // Start the script, adding all requested namespaces StringBuilder scriptBuilder = new StringBuilder(); scriptBuilder.AppendLine(string.Join(Environment.NewLine, namespaces.Select(x => "using " + x + ";"))); if (declarations != null) { scriptBuilder.AppendLine(declarations); } scriptBuilder.Append(@" public static class ConfigScript { public static void Run(IDictionary<string, object> Metadata, IPipelineCollection Pipelines, string RootFolder, string InputFolder, string OutputFolder) {" + Environment.NewLine + script + @" }"); // Add static methods to construct each module // Use Roslyn to get a display string for each constructor foreach (Type moduleType in moduleTypes) { scriptBuilder.Append(GenerateModuleConstructorMethods(moduleType)); } scriptBuilder.Append("}"); // Need to replace all instances of module type method name shortcuts to make them fully-qualified SyntaxTree scriptTree = CSharpSyntaxTree.ParseText(scriptBuilder.ToString()); ConfigRewriter configRewriter = new ConfigRewriter(moduleTypes); script = configRewriter.Visit(scriptTree.GetRoot()).ToFullString(); return script; }
public static string Generate(string declarations, string config, HashSet<Type> moduleTypes, IEnumerable<string> namespaces) { // Start the script, adding all requested namespaces StringBuilder scriptBuilder = new StringBuilder(); scriptBuilder.AppendLine(string.Join(Environment.NewLine, namespaces.Select(x => "using " + x + ";"))); if (!string.IsNullOrWhiteSpace(declarations)) { scriptBuilder.AppendLine(declarations); } scriptBuilder.Append(@" public class ConfigScript : ConfigScriptBase { public ConfigScript(IEngine engine) : base(engine) { } public override void Run() {" + Environment.NewLine + config + @" }"); // Add static methods to construct each module Dictionary<string, string> moduleNames = new Dictionary<string, string>(); foreach (Type moduleType in moduleTypes) { scriptBuilder.Append(GenerateModuleConstructorMethods(moduleType, moduleNames)); } scriptBuilder.Append("}"); // Need to replace all instances of module type method name shortcuts to make them fully-qualified SyntaxTree scriptTree = CSharpSyntaxTree.ParseText(scriptBuilder.ToString()); ConfigRewriter configRewriter = new ConfigRewriter(moduleTypes); return configRewriter.Visit(scriptTree.GetRoot()).ToFullString(); }