private string ProcessCode(Base parent, string body) { if (!(parent is Namespace)) { throw new InvalidOperationException("C# code is only accepted inside a namespace"); } var split = Regex.Split(body, "(.+?{.+})\\s*(.*)"); var code = "public " + split[1]; parent.Codes.Add(code); return split[2]; }
private string ProcessUsing(Base parent, string body) { if (!(parent is Namespace) && !(parent is Compiler)) { throw new InvalidOperationException("using must be inside a namespace or root."); } var split = Regex.Split(body, "([\\w\\.]+);\\s+(.*)"); parent.Imports.Add(split[1]); return split[2]; }
private CodeTypeDeclaration CompileTasks(Binary binary, string parent, List<Task> tasks, Base namespc, CodeNamespace codeNamespace, CodeTypeDeclaration parentType) { var className = string.Format("Class_{0}", namespc.Name); CodeTypeDeclaration type = GetTypeDeclaration(parentType, className); if (type == null) { type = new CodeTypeDeclaration(); type.IsClass = true; type.Name = string.Format("Class_{0}", namespc.Name); type.Attributes = MemberAttributes.Public; } foreach (var task in tasks) { var key = string.Format("{0}{1}{2}", parent, !string.IsNullOrEmpty(parent) ? ":" : "", task.Name); binary.Tasks.Add(new CompiledTask() { Key = key, MethodName = string.Format("Call_{0}", key.Replace(":", "_")), ClassName = type.Name //Compiled = CompileTask(namespc, task.Body) }); var method = new CodeMemberMethod(); method.Name = string.Format("Call_{0}", key.Replace(":", "_")); method.Attributes = MemberAttributes.Public; method.Statements.Add(new CodeSnippetStatement(task.Body)); type.Members.Add(method); } return type; }
private string ProcessTask(Base parent, string body) { var split = Regex.Split(body, ":(\\w+)\\s+do\\s+(.+?)\\s+end\\s*(.*)\\s*"); var task = new Task() { Body = split[2], Name = split[1], Description = tempDescription }; parent.Tasks.Add(task); tempDescription = string.Empty; return split[3]; }
private CompilerResults CompileTask(Base namespc, string code) { var codeNamespace = new CodeNamespace("Unahi.CRake.RuntimeGenerated"); var codeUnit = new CodeCompileUnit(); codeUnit.Namespaces.Add(codeNamespace); var compiler = CodeDomProvider.CreateProvider("CSharp"); var parameters = new CompilerParameters(Require.ToArray()); foreach (var item in namespc.Imports) { codeNamespace.Imports.Add(new CodeNamespaceImport(item)); } var type = new CodeTypeDeclaration(); type.IsClass = true; type.Name = "Namespace"; type.Attributes = MemberAttributes.Public; codeNamespace.Types.Add(type); var testMethod = new CodeMemberMethod(); testMethod.Name = "DynamicMethod"; testMethod.Attributes = MemberAttributes.Public; testMethod.Statements.Add(new CodeSnippetStatement(code)); type.Members.Add(testMethod); return compiler.CompileAssemblyFromDom(parameters, codeUnit); }