Skip to content

CodeDomUtilities

Namespace: SideXP.Core.EditorOnly

public static class CodeDomUtilities

Miscellaneous utility functions for working with code generation.

Methods

GetTypeReference(Type, CodeNamespace, CodeNamespace, bool, bool)

public static CodeTypeReference GetTypeReference(Type type, CodeNamespace importsNamespace, CodeNamespace domNamespace = null, bool fullyQualified = false, bool skipImport = false)

Creates a type reference, importing that type if it's not yet.

Parameters

  • type: The type to reference.
  • importsNamespace: The namespace used to store the import statements. A new import statement will be added to it if the given type is not already imported.
  • fullyQualified: By default, the type will be referenced using its name, not its full name (including the namespace). If checked, the type will be referenced using its full name, skipping the import step (since the namespace will be explicit).
  • skipImport: By default, if the given type is not imported, a new import statement is added to the given imports namespace. If checked or fullyQualified is enabled, this default behavior is skipped (but the output type name will be processed as expected).
  • domNamespace: The namespace used to store the actual classes to generate. This is used by this function to check if the named namespace is already included in that namespace.

Returns

Returns the created type reference.

Remarks

This function will also remove the "-Attribute" suffix for types that inherit from Attribute.

ContainsImport(Type, CodeNamespace, CodeNamespace)

public static bool ContainsImport(Type type, CodeNamespace importsNamespace, CodeNamespace domNamespace = null)

Checks the namespace of a given type is imported in the script being generated.

Parameters

  • type: The type to check.

ContainsImport(string, CodeNamespace, CodeNamespace)

public static bool ContainsImport(string namespaceStr, CodeNamespace importsNamespace, CodeNamespace domNamespace = null)

Checks if a given namespace is imported in the script being generated.

Parameters

  • namespaceStr: The namespace to check.
  • importsNamespace: The namespace used to store the import statements.
  • domNamespace: The namespace used to store the actual classes to generate. This is used by this function to check if the named namespace is already included in that namespace.

Returns

Returns true if the named namespace is included in import statements.

CreateParameter(Type, string, CodeNamespace, CodeNamespace)

public static CodeParameterDeclarationExpression CreateParameter(Type type, string name, CodeNamespace importsNamespace, CodeNamespace domNamespace = null)

Creates a parameter declaration, importing that type if it's not yet.

Parameters

  • type: The type of the parameter.
  • name: The name of the parameter.

Returns

Returns the created parameter declaration.

CreateParameter(ParameterInfo, CodeNamespace, CodeNamespace)

public static CodeParameterDeclarationExpression CreateParameter(ParameterInfo param, CodeNamespace importsNamespace, CodeNamespace domNamespace = null)

Creates a parameter declaration, importing that type if it's not yet, and using the appropriate keyword depending on the parameter direction.

Parameters

  • param: Informations about the parameter.

InheritFrom(CodeTypeDeclaration, Type, CodeNamespace, CodeNamespace, bool)

public static bool InheritFrom(CodeTypeDeclaration inheritorClass, Type parent, CodeNamespace importsNamespace, CodeNamespace domNamespace = null, bool noOverride = false)

Appends a given base type to the a given class.

Parameters

  • inheritorClass: The class that will inherit from the given parent type.
  • parent: The type from which the given inheritor class should inherit.
  • noOverride: By default, the system will try to implement all the abstract functions and properties of the given base type, if it is abstract itself. If checked, this step is skipped, but may cause the script to not compile.

Returns

Returns true if the base type has been added successfully.

OverrideAbstractProperties(CodeTypeDeclaration, Type, CodeNamespace, CodeNamespace)

public static bool OverrideAbstractProperties(CodeTypeDeclaration inheritorClass, Type parent, CodeNamespace importsNamespace, CodeNamespace domNamespace = null)

Overrides all the abstract properties declared in a given parent type.

Parameters

  • inheritorClass: The class that will contain the overrides.
  • parent: The type from which to override the properties.

Returns

Returns true if at least one property has been overriden successfully.

OverrideAbstractMethods(CodeTypeDeclaration, Type, CodeNamespace, CodeNamespace)

public static bool OverrideAbstractMethods(CodeTypeDeclaration inheritorClass, Type parent, CodeNamespace importsNamespace, CodeNamespace domNamespace = null)

Overrides all the abstract methods declared in a given parent type.

Parameters

  • inheritorClass: The class that will contain the overrides.
  • parent: The type from which to override the methods.

Returns

Returns true if at least one method has been overriden successfully.