public void ReplaceReferenceGlobalStringsInFile(string iFilepath, string iReferenceName, ref List <ReferenceStruct> iReferences) { List <string> itext = Utilities.TextFileReader(iFilepath); List <string> globals = new List <string>(); for (int i = 0; i < iReferences.Count; i++) { if (iReferences[i].name == iReferenceName) { Translate.GlobalsRename(iReferenceName + ".GlobalVars.", ref itext, iReferences[i].globals, iReferences[i].types); } } File.WriteAllLines(iFilepath, itext, Encoding.UTF8); }
//Convert a script to C# public List <string> Write(Script iscript, string inamespace, ref List <string> oglobal_names, ref List <string> oglobals, ref List <string> olocal_names, ref List <string> olocals, ref List <string> iStandardReferences, ref List <List <string> > iStandardCSReferences) { List <string> tout = new List <string>(); //Header tout.Add("/**Header Start"); for (int i = 0; i < iscript.header.Count; i++) { tout.Add(iscript.header[i]); } tout.Add("Header End**/"); tout.Add(""); //References tout.Add(""); tout.Add("/*References Start*/"); //Add standard references for (int i = 0; i < standard_references.Count; i++) { tout.Add("using " + standard_references[i] + ";"); } //Process rest for (int i = 0; i < iscript.includes.Count; i++) { ProcessReference(iscript.includes[i], ref iStandardReferences, ref iStandardCSReferences); } for (int i = 0; i < project_references.Count; i++) { tout.Add("using " + project_references[i] + ";"); } tout.Add("/*References End*/"); tout.Add(""); //Types tout.Add("/*Types Start*/"); for (int i = 0; i < iscript.classes[0].types.Count; i++) { tout.Add(Utilities.Beautify_Delphi2CS(Utilities.Delphi2CSRules(TypeToString(iscript.classes[0].types[i])).Replace(";;", ";")).Replace("==", "=").Trim()); } for (int i = 0; i < iscript.classes[1].types.Count; i++) { tout.Add(Utilities.Beautify_Delphi2CS(Utilities.Delphi2CSRules(TypeToString(iscript.classes[1].types[i])).Replace(";;", ";")).Replace("==", "=").Trim()); } tout.Add("/*Types End*/"); tout.Add(""); //Namespace tout.Add("namespace " + inamespace); tout.Add("{"); //Global Constants, Variables and Enums ProcessGlobals(iscript.classes[0], ref oglobals, ref oglobal_names); //Local Constants, Variables and Enums ProcessGlobals(iscript.classes[1], ref olocals, ref olocal_names); List <string> telement_names = new List <string>(); string classtype = ""; classtype = "class"; tout.Add(""); tout.Add("//Class GlobalVars"); int tGlobalVarInsert = tout.Count; List <string> tGlobalVarClass = new List <string>(); tGlobalVarClass.Add(Indent(4) + "public " + classtype + " GlobalVars"); tGlobalVarClass.Add(Indent(4) + "{"); tGlobalVarClass.AddRange(WriteClassBody(iscript.classes[0], ref telement_names)); tGlobalVarClass.AddRange(WriteClassBody(iscript.classes[1], ref telement_names)); tGlobalVarClass.Add(Indent(4) + "}"); //Classes for (int i = 2; i < iscript.classes.Count; i++) { bool tHasBaseclass = true; if ((iscript.classes[i].baseclass == null) || (iscript.classes[i].baseclass == "") || (iscript.classes[i].baseclass == "null")) { tHasBaseclass = false; } classtype = ""; if ((iscript.classes[i].type == "c")) { classtype = "class"; } else if ((iscript.classes[i].type == "r")) { classtype = "struct"; } else { classtype = "interface"; } //Handle constructor tout.Add(""); tout.Add("//Class " + iscript.classes[i].name); //Classes / Interfaces //Inheritance if (!tHasBaseclass) { tout.Add(Indent(4) + "public " + classtype + " " + iscript.classes[i].name); } else { tout.Add(Indent(4) + "public " + classtype + " " + iscript.classes[i].name + " : " + iscript.classes[i].baseclass); } tout.Add(Indent(4) + "{"); telement_names = new List <string>(); tout.AddRange(WriteClassBody(iscript.classes[i], ref telement_names)); tout.Add(Indent(4) + "}"); } tout.Add("}"); List <string> temptytypeslist = new List <string>(); //Replace the local Globals used in the text Translate.GlobalsRename(inamespace + ".GlobalVars.", ref tout, olocal_names, temptytypeslist); tout.InsertRange(tGlobalVarInsert, tGlobalVarClass); return(tout); }