FRBDK/Glue/GumPlugin/GumPlugin/Managers/CodeGeneratorManager.cs
/// <summary>
/// Generates and saves the code for the passed Gum ElementSave (both generated and custom code template), 
/// but does not add the resulting .cs files to the VisualStudio project.
/// </summary>
/// <param name="element">The element to generate.</param>
/// <returns>Information about what was generated and saved.</returns>
Generates and saves the code for the passed Gum ElementSave (both generated and custom code template),
but does not add the resulting .cs files to the VisualStudio project.
Generates and saves the code for the passed Gum ElementSave ( both generated and custom code template ) but does not add the resulting . cs files to the VisualStudio project .
public GenerationResult GenerateCodeFor(Gum.DataTypes.ElementSave element, 
            CodeGenerationSavingBehavior savingBehavior = CodeGenerationSavingBehavior.AlwaysSave)
        {
            GenerationResult resultToReturn = new GenerationResult();
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            string directoryToSave = GumRuntimesFolder;
            string generatedCode = mGueDerivingClassCodeGenerator.GenerateCodeFor(element);
            FilePath generatedSaveLocation = directoryToSave + element.Name + "Runtime.Generated.cs";
            if (savingBehavior == CodeGenerationSavingBehavior.AlwaysSave)
            {
                resultToReturn.DidSaveGenerated = true;
            }
            else 
            {
                if(!generatedSaveLocation.Exists())
                {
                    resultToReturn.DidSaveGenerated = true;
                }
                else
                {
                    var existingText = File.ReadAllText(generatedSaveLocation.FullPath);
                    resultToReturn.DidSaveGenerated = existingText != generatedCode;
                }
            }
            string customCodeSaveLocation = directoryToSave + element.Name + "Runtime.cs";
            if (!System.IO.File.Exists(customCodeSaveLocation) && 
                (element is StandardElementSave) == false)
            {
                resultToReturn.DidSaveCustom = true;
            }
            if(string.IsNullOrEmpty(generatedCode))
            {
                resultToReturn.DidSaveCustom = false;
                resultToReturn.DidSaveGenerated = false;
            }
            if (resultToReturn.DidSaveGenerated)
            {
                var directory = generatedSaveLocation.GetDirectoryContainingThis();
                System.IO.Directory.CreateDirectory(directory.FullPath);
                GlueCommands.Self.TryMultipleTimes(() => 
                    System.IO.File.WriteAllText(generatedSaveLocation.FullPath, generatedCode));
            }
            if(resultToReturn.DidSaveCustom)
            {
                var customCode = CustomCodeGenerator.Self.GetCustomCodeTemplateCode(element);
                GlueCommands.Self.TryMultipleTimes(() =>
                    System.IO.File.WriteAllText(customCodeSaveLocation, customCode));
            }
            return resultToReturn;
        }
public GenerationResult GenerateCodeFor ( Gum . DataTypes . ElementSave element , CodeGenerationSavingBehavior savingBehavior = CodeGenerationSavingBehavior . AlwaysSave ) { GenerationResult resultToReturn = new GenerationResult ( ) ; if ( element == null ) { throw new ArgumentNullException ( nameof ( element ) ) ; } string directoryToSave = GumRuntimesFolder ; string generatedCode = mGueDerivingClassCodeGenerator . GenerateCodeFor ( element ) ; FilePath generatedSaveLocation = directoryToSave + element . Name + " " ; if ( savingBehavior == CodeGenerationSavingBehavior . AlwaysSave ) { resultToReturn . DidSaveGenerated = true ; } else { if ( ! generatedSaveLocation . Exists ( ) ) { resultToReturn . DidSaveGenerated = true ; } else { var existingText = File . ReadAllText ( generatedSaveLocation . FullPath ) ; resultToReturn . DidSaveGenerated = existingText != generatedCode ; } } string customCodeSaveLocation = directoryToSave + element . Name + " " ; if ( ! System . IO . File . Exists ( customCodeSaveLocation ) && ( element is StandardElementSave ) == false ) { resultToReturn . DidSaveCustom = true ; } if ( string . IsNullOrEmpty ( generatedCode ) ) { resultToReturn . DidSaveCustom = false ; resultToReturn . DidSaveGenerated = false ; } if ( resultToReturn . DidSaveGenerated ) { var directory = generatedSaveLocation . GetDirectoryContainingThis ( ) ; System . IO . Directory . CreateDirectory ( directory . FullPath ) ; GlueCommands . Self . TryMultipleTimes ( ( ) => System . IO . File . WriteAllText ( generatedSaveLocation . FullPath , generatedCode ) ) ; } if ( resultToReturn . DidSaveCustom ) { var customCode = CustomCodeGenerator . Self . GetCustomCodeTemplateCode ( element ) ; GlueCommands . Self . TryMultipleTimes ( ( ) => System . IO . File . WriteAllText ( customCodeSaveLocation , customCode ) ) ; } return resultToReturn ; }
Generates and saves the code for the passed Gum ElementSave (both generated and custom code template),
but does not add the resulting .cs files to the VisualStudio project.
Generates and saves the code for the passed Gum ElementSave ( both generated and custom code template ) but does not add the resulting . cs files to the VisualStudio project .
// if(savingBehavior == CodeGenerationSavingBehavior.SaveIfGeneratedDiffers) // We only want to save this file if what we've just generated is different than what is already on disk: // If it doesn't exist, overwrite it. If it does exist, don't overwrite it - we might lose // custom code. // Standard elements don't have CustomInit   // in case directory doesn't exist
Information about what was generated and saved.
Information about what was generated and saved .
element
Gum.DataTypes.ElementSave
The element to generate.
The element to generate .
savingBehavior
CodeGenerationSavingBehavior