Skip to content

CodeGenerationUtility

Namespace: SideXP.Core.EditorOnly

public static class CodeGenerationUtility

Miscellaneous utility functions for generating code, following our standards.

Fields

CompileUnitOptions

public static readonly CodeGeneratorOptions CompileUnitOptions

The options used by default by the script generator.

Methods

MakeScriptCompileUnit(CodeNamespace, CodeNamespace)

public static CodeCompileUnit MakeScriptCompileUnit(out CodeNamespace importsNamespace, out CodeNamespace domNamespace)

Creates a C# CodeDom compile unit used to generate a script.

Parameters

  • importsNamespace: Outputs the global namespace used to list the using statements.
  • domNamespace: Outputs the namespace where the class is generated. Can be the same as the imports namespace if the related type is not provided or doesn't have a namespace.

Returns

Returns the created CodeDom compile unit.

MakeScriptCompileUnit(Type, CodeNamespace, CodeNamespace)

public static CodeCompileUnit MakeScriptCompileUnit(Type relatedType, out CodeNamespace importsNamespace, out CodeNamespace domNamespace)

Creates a C# CodeDom compile unit used to generate a script.

Parameters

  • relatedType: The type to which the class is related. Used to set the same namespace for the script to generate.
  • importsNamespace: Outputs the global namespace used to list the using statements.
  • domNamespace: Outputs the namespace where the class is generated. Can be the same as the imports namespace if the related type is not provided or doesn't have a namespace.

Returns

Returns the created CodeDom compile unit.

GenerateScript(CodeCompileUnit)

public static string GenerateScript(CodeCompileUnit compileUnit)

Generates a script from a given CodeCompileUnit.

Parameters

  • compileUnit: The compile unit used to generate the script.

Returns

Returns the generated script content.

GenerateScriptFile(string, CodeCompileUnit)

public static bool GenerateScriptFile(string path, CodeCompileUnit compileUnit)

Generates a script file from a given CodeCompileUnit.

Parameters

  • path: The path to the script file to generate.
  • compileUnit: The compile unit used to generate the script.

Returns

Returns true if the script has been generated successfully.

RemoveAutocomment(string)

public static void RemoveAutocomment(ref string scriptContent)

Removes the comment added by C# code DOM provider when generating a script.

Parameters

  • scriptContent: The content of the script as a string. Modified in place to strip the auto-comment.

RemoveAutocommentFromFile(string)

public static void RemoveAutocommentFromFile(string path)

Removes the comment added by C# code DOM provider when generating a script.

Parameters

  • path: The path to the generated file.

FixBlankLines(string)

public static void FixBlankLines(ref string scriptContent)

Removes excess blank lines and adds one between closing brackets.

Parameters

  • scriptContent: The content of the script as a string.