public void TestCode() { var codeFile = new CodeDocument { TabCharacter = " " }; codeFile.Namespace("Test") .Class("public", "TestClass", "") ._() ._("private string _value;") ._() .Function("public", "TestClass", "string value") ._("_value = value;") .End() ._() .Function("public void ", "TestMethod", "") ._("_value = 5;") .End() ._() ._() .Interface("public", "TestInterface", "") ._("void TestMethod();") .End() .End() .End(); Debug.WriteLine(codeFile.ToString()); Assert.IsTrue(true); }
public static void CreateEmptyCodeIfNecessary(IElement currentElement, string fullFileName, bool forceRegenerateContents) { bool doesFileExist = File.Exists(fullFileName); if (!doesFileExist) { PluginManager.ReceiveOutput("Forcing a regneration of " + fullFileName + " because Glue can't find it anywhere."); // There is no shared code file for this event, so we need to make one ProjectManager.CodeProjectHelper.CreateAndAddPartialCodeFile(fullFileName, true); } if (!doesFileExist || forceRegenerateContents) { string namespaceString = GlueCommands.Self.GenerateCodeCommands.GetNamespaceForElement(currentElement); ICodeBlock templateCodeBlock = new CodeDocument(); EventCodeGenerator.AddUsingStatementsToBlock(templateCodeBlock); ICodeBlock namespaceCB = templateCodeBlock.Namespace(namespaceString); ICodeBlock classCB = namespaceCB.Class("public partial", currentElement.ClassName, null); classCB ._() .End() .End(); string templateToSave = templateCodeBlock.ToString(); FlatRedBall.Glue.IO.FileWatchManager.IgnoreNextChangeOnFile(fullFileName); FileManager.SaveText(templateToSave, fullFileName); } // Add if it isn't part of the project const bool saveFile = false; // don't save it - we just want to make sure it's part of the project ProjectManager.CodeProjectHelper.CreateAndAddPartialCodeFile(fullFileName, saveFile); }
private string GetStringsGeneratedCodeFileContents(ReferencedFileSave referencedFileSave) { var glueState = Container.Get <IGlueState>(); var glueCommands = Container.Get <IGlueCommands>(); string toReturn = null; if (referencedFileSave != null) { var namespaceName = $"{glueState.ProjectNamespace}.DataTypes"; ICodeBlock document = new CodeDocument(0); ICodeBlock codeBlock = document.Namespace(namespaceName); codeBlock = codeBlock.Class("Strings"); string fileName = glueCommands.GetAbsoluteFileName(referencedFileSave); var doesFileExist = System.IO.File.Exists(fileName); if (System.IO.File.Exists(fileName)) { var runtime = CsvFileManager.CsvDeserializeToRuntime(fileName); foreach (var row in runtime.Records) { TryAddMemberForRow(codeBlock, row); } toReturn = document.ToString(); } } return(toReturn); }