Table of Contents

Class NamespaceGenerator<T>

Namespace
NMF.CodeGen
Assembly
NMF.CodeGen.dll

Represents a transformation rule that generates namespaces

public abstract class NamespaceGenerator<T> : TransformationRule<T, CodeNamespace> where T : class

Type Parameters

T

The model element type from which namespaces are being generated

Inheritance
NamespaceGenerator<T>
Derived
Inherited Members

Constructors

NamespaceGenerator()

Creates a new instance

protected NamespaceGenerator()

Properties

AssembliesToCheck

Gets the assemblies in which to check for system name conflicts

protected virtual IEnumerable<Assembly> AssembliesToCheck { get; }

Property Value

IEnumerable<Assembly>

DefaultImports

Gets the default namespace imports in a derived class

public abstract IEnumerable<string> DefaultImports { get; }

Property Value

IEnumerable<string>

Methods

CreateOutput(T, ITransformationContext)

Creates the uninitialized transformation rule output

public override CodeNamespace CreateOutput(T input, ITransformationContext context)

Parameters

input T

The input model element

context ITransformationContext

The transformation context

Returns

CodeNamespace

A blank code namespace with the correct name

GetName(T)

Gets the name for the code namespace generated from the given model element

protected abstract string GetName(T input)

Parameters

input T

The input model element

Returns

string

The name of the code namespace

GetNamespaceConflictsIdentifier()

Gets the identifier for namespace conflicts

protected virtual object GetNamespaceConflictsIdentifier()

Returns

object

An object that is used to obtain namespace conflicts

IsNamespaceConflict(string, CodeNamespace)

Decides whether the given name causes a namespace conflict

protected virtual bool IsNamespaceConflict(string name, CodeNamespace ns)

Parameters

name string

The proposed name

ns CodeNamespace

The namespace

Returns

bool

True, if there is a namespace conflict so that the given name must be fully qualified, otherwise False

IsSystemNameConflict(string, string)

Determines whether the given type name is a conflict with a system type

protected virtual bool IsSystemNameConflict(string typeName, string refNs)

Parameters

typeName string
refNs string

the suggested namespace

Returns

bool

IsValidName(string, CodeNamespace)

Decides whether the given name is a valid class name for a type

protected virtual bool IsValidName(string name, CodeNamespace ns)

Parameters

name string

The proposed name

ns CodeNamespace

The proposed namespace

Returns

bool

True if the name is valid, otherwise False

RequireType<TType>(TransformationRuleBase<TType, CodeTypeDeclaration>, Func<T, TType>)

Creates a dependency that the given subsequent model element is transformed to a type

public ITransformationRuleDependency RequireType<TType>(TransformationRuleBase<TType, CodeTypeDeclaration> rule, Func<T, TType> selector) where TType : class

Parameters

rule TransformationRuleBase<TType, CodeTypeDeclaration>

The transformation rule used to generate the type

selector Func<T, TType>

A function selecting the correct subsequent model element

Returns

ITransformationRuleDependency

The created transformation rule dependency

Type Parameters

TType

The model element of the input type

RequireTypes<TType>(TransformationRuleBase<TType, CodeTypeDeclaration>, Func<T, IEnumerable<TType>>)

Creates a dependency that the given subsequent model elements are transformed to types

public ITransformationRuleDependency RequireTypes<TType>(TransformationRuleBase<TType, CodeTypeDeclaration> rule, Func<T, IEnumerable<TType>> selector) where TType : class

Parameters

rule TransformationRuleBase<TType, CodeTypeDeclaration>

The transformation rule used to generate the types

selector Func<T, IEnumerable<TType>>

A function that selects the subsequent model elements

Returns

ITransformationRuleDependency

The created transformation rule dependency

Type Parameters

TType

The model elements input type

Transform(T, CodeNamespace, ITransformationContext)

Initializes the generated code namespace

public override void Transform(T input, CodeNamespace output, ITransformationContext context)

Parameters

input T

The input model element

output CodeNamespace

The generated code namespace

context ITransformationContext

The transformation context