CodeGenerationTools

Responsible for helping to create source code that is correctly formatted and functional

Syntax

public static class CodeGenerationTools

Inheritance

Properties

CamelCaseFields

public static bool CamelCaseFields { get; set; }
When true, the field names are Camel Cased, otherwise they will preserve the case they start with. Default is true.

Returns

bool

FullyQualifySystemTypes

public static bool FullyQualifySystemTypes { get; set; }
When true, all types that are not being generated are fully qualified to keep them from conflicting with types that are being generated. Useful when you have something like a type being generated named System. Default is false.

Returns

bool

Methods

AbstractOption

public static string AbstractOption(EntityType entity)
Returns the abstract option if the entity is Abstract, otherwise returns String.Empty.

Parameters

Returns

string

AdminControllerClassDeclaration

public static string AdminControllerClassDeclaration(string dbContextName, bool addInheritance = false, string baseClass = null)
Generates the class declaration for an Admin API controller.

Parameters

  • dbContextName string: The name of the DbContext class.
  • addInheritance bool: Whether to include inheritance in the class declaration.
  • baseClass string: The name of the base class to inherit from. Defaults to the value in CodeGenConstants.ApiBaseClassName.

Returns

string The class declaration string for the Admin API controller.

AuthorizationClassDeclaration

public static string AuthorizationClassDeclaration(EntityContainer container)

Parameters

Returns

string

BusinessDependencyClassDeclaration

public static string BusinessDependencyClassDeclaration(string projectName)

Parameters

Returns

string

CamelCase

public static string CamelCase(string identifier)
Returns the passed in identifier with the first letter changed to lowercase.

Parameters

Returns

string

ControllerClassDeclaration

public static string ControllerClassDeclaration(string dbContextName, bool addInheritance = false, string baseClass = null)
Generates the class declaration for an API controller.

Parameters

  • dbContextName string: The name of the DbContext class.
  • addInheritance bool: Whether to include inheritance in the class declaration.
  • baseClass string: The name of the base class to inherit from. Defaults to the value in CodeGenConstants.ApiBaseClassName.

Returns

string The class declaration string for the API controller.

CreateFullName

public static string CreateFullName(string namespaceName, string name)
Returns as full of a name as possible, if a namespace is provided the namespace and name are combined with a period, otherwise just the name is returned.

Parameters

Returns

string

CreateLiteral

public static string CreateLiteral(object value)
Retuns a literal representing the supplied value.

Parameters

Returns

string

DbContextClassDeclaration

public static string DbContextClassDeclaration(EntityContainer container)

Parameters

Returns

string

DbSet

public static string DbSet(EntitySet entitySet)

Parameters

Returns

string

EntityClassDeclaration

public static string EntityClassDeclaration(EntityComposition entity)
Creates the class declaration for a given .

Parameters

  • entity EntityComposition: The instance that contains the EasyAF breakdowns plus the EDMX model metadata for a given Entity.

Returns

string A string that contains the Entity class’ name and base types.

Escape

public static string Escape(EdmFunction function)
Returns the name of the EdmFunction that is safe for use as an identifier.

Parameters

Returns

string

Escape

public static string Escape(EdmMember member)
Returns the name of the EdmMember that is safe for use as an identifier.

Parameters

Returns

string

Escape

public static string Escape(EdmType type)
Returns the name of the EdmType that is safe for use as an identifier.

Parameters

Returns

string

Escape

public static string Escape(EntityContainer container)
Returns the name of the EntityContainer that is safe for use as an identifier.

Parameters

Returns

string

Escape

public static string Escape(EntitySet set)
Returns the name of the EntitySet that is safe for use as an identifier.

Parameters

Returns

string

Escape

public static string Escape(EnumMember member)
Returns the name of the EnumMember that is safe for use as an identifier.

Parameters

Returns

string

Escape

public static string Escape(string name)
Returns a string that is safe for use as an identifier in C#. Keywords are escaped.

Parameters

Returns

string

Escape

public static string Escape(StructuralType type)
Returns the name of the StructuralType that is safe for use as an identifier.

Parameters

Returns

string

Escape

public static string Escape(Type clrType, bool fullyQualifySystemTypes)
Returns the name of the Type object formatted for use in source code.

Parameters

  • clrType Type:
  • fullyQualifySystemTypes bool:

Returns

string

Escape

public static string Escape(Type clrType)
Returns the name of the Type object formatted for use in source code.

Parameters

Returns

string

Escape

public static string Escape(TypeUsage typeUsage, bool ignoreNullables = false)
Returns the name of the TypeUsage’s EdmType that is safe for use as an identifier.

Parameters

Returns

string

EscapeNamespace

public static string EscapeNamespace(string namespaceName)
Returns the NamespaceName with each segment safe to use as an identifier.

Parameters

Returns

string

FieldName

public static string FieldName(EdmMember member)
Returns the name of the EdmMember formatted for use as a field identifier. This method changes behavior based on the CamelCaseFields setting.

Parameters

Returns

string

FieldName

public static string FieldName(EntitySet set)
Returns the name of the EntitySet formatted for use as a field identifier. This method changes behavior based on the CamelCaseFields setting.

Parameters

Returns

string

FieldName

public static string FieldName(EntityType entityType)
Returns the name of the EntitySet formatted for use as a field identifier. This method changes behavior based on the CamelCaseFields setting.

Parameters

Returns

string

GetAllGlobalItems

public static IEnumerable<string> GetAllGlobalItems(EdmItemCollection itemCollection)
Returns the names of the items in the supplied collection that correspond to O-Space types.

Parameters

Returns

IEnumerable<string>

GetGlobalItemName

public static string GetGlobalItemName(GlobalItem item)
Returns the name of the supplied GlobalItem.

Parameters

Returns

string

GetItemsToGenerate<T>

public static IEnumerable<T> GetItemsToGenerate<T>(ItemCollection itemCollection) where T : GlobalItem
Gets the entity, complex, or enum types for which code should be generated from the given item collection. Any types for which an ExternalTypeName annotation has been applied in the conceptual model metadata (CSDL) are filtered out of the returned list.

Parameters

Returns

IEnumerable<T> The items to generate.

GetTypeName

public static string GetTypeName(EdmType edmType, string modelNamespace)
Returns the escaped type name to use for the given c-space type in o-space. This might be an external type name if the ExternalTypeName annotation has been specified in the conceptual model metadata (CSDL).

Parameters

  • edmType EdmType: The c-space type to get a name for.
  • modelNamespace string: If not null and the type’s namespace does not match this namespace, then a fully qualified name will be returned.

Returns

string The type name to use.

GetTypeName

public static string GetTypeName(EdmType edmType)
Returns the escaped type name to use for the given c-space type in o-space. This might be an external type name if the ExternalTypeName annotation has been specified in the conceptual model metadata (CSDL).

Parameters

  • edmType EdmType: The c-space type to get a name for.

Returns

string The type name to use.

GetTypeName

public static string GetTypeName(TypeUsage typeUsage, string modelNamespace)
Returns the escaped type name to use for the given usage of an c-space type in o-space. This might be an external type name if the ExternalTypeName annotation has been specified in the conceptual model metadata (CSDL).

Parameters

  • typeUsage TypeUsage: The c-space type usage to get a name for.
  • modelNamespace string: If not null and the type’s namespace does not match this namespace, then a fully qualified name will be returned.

Returns

string The type name to use.

GetTypeName

public static string GetTypeName(TypeUsage typeUsage)
Returns the escaped type name to use for the given usage of a c-space type in o-space. This might be an external type name if the ExternalTypeName annotation has been specified in the conceptual model metadata (CSDL).

Parameters

  • typeUsage TypeUsage: The c-space type usage to get a name for.

Returns

string The type name to use.

ManagerClassDeclaration

public static string ManagerClassDeclaration(EntityComposition entity, string dbContextTypeName)
Creates the class declaration for a given .

Parameters

  • entity EntityComposition: The instance that contains the EasyAF breakdowns plus the EDMX model metadata for a given Entity.
  • dbContextTypeName string:

Returns

string A string that contains the Entity class’ name and base types.

ModelBuilderClassDeclaration

public static string ModelBuilderClassDeclaration(EntityContainer container)

Parameters

Returns

string

PropertyVirtualModifier

public static string PropertyVirtualModifier(string accessibility)

Parameters

Returns

string

RestierDependencyClassDeclaration

public static string RestierDependencyClassDeclaration(string projectName)

Parameters

Returns

string

SpaceAfter

public static string SpaceAfter(string value)
If the value parameter is null or empty an empty string is returned, otherwise it retuns value with a single space concatenated on the end.

Parameters

Returns

string

SpaceBefore

public static string SpaceBefore(string value)
If the value parameter is null or empty an empty string is returned, otherwise it retuns value with a single space concatenated on the end.

Parameters

Returns

string

StringAfter

public static string StringAfter(string value, string append)
If the value parameter is null or empty an empty string is returned, otherwise it retuns value with append concatenated on the end.

Parameters

Returns

string

StringBefore

public static string StringBefore(string prepend, string value)
If the value parameter is null or empty an empty string is returned, otherwise it retuns value with prepend concatenated on the front.

Parameters

Returns

string