Table of Contents

Class ClassGenerator<T>

Namespace
NMF.CodeGen
Assembly
NMF.CodeGen.dll

Represents a base class for a transformation rule that generates classes

public abstract class ClassGenerator<T> : TransformationRule<T, CodeTypeDeclaration> where T : class

Type Parameters

T

The model element type from which the classes are generated

Inheritance
ClassGenerator<T>
Derived
Inherited Members

Methods

AddImplementationBaseClass(CodeTypeDeclaration)

Modifies the given code declaration to respect that the generated class is the root of an inheritance tree

protected virtual void AddImplementationBaseClass(CodeTypeDeclaration generatedType)

Parameters

generatedType CodeTypeDeclaration

The generated class declaration

Remarks

This method can be overridden so that the derived transformation rule can inherit common base functionality

CreateInterfaceMembers(T, CodeTypeDeclaration, CodeTypeDeclaration, ITransformationContext)

Generates the interface members for the given type

protected virtual void CreateInterfaceMembers(T input, CodeTypeDeclaration generatedType, CodeTypeDeclaration interfaceDecl, ITransformationContext context)

Parameters

input T

The input for which the interface members need to be generated

generatedType CodeTypeDeclaration

The generated type

interfaceDecl CodeTypeDeclaration

The interface declaration

context ITransformationContext

The transformation context

CreateOutput(T, ITransformationContext)

Creates the output the transformation rule

public override CodeTypeDeclaration CreateOutput(T input, ITransformationContext context)

Parameters

input T

The input model element

context ITransformationContext

The transformaton context

Returns

CodeTypeDeclaration

A new code type declaration with set reference that references back to the code declaration

CreateSeparatePublicInterface(T, CodeTypeDeclaration)

Create a separate public interface for the given input

protected virtual CodeTypeDeclaration CreateSeparatePublicInterface(T input, CodeTypeDeclaration generatedType)

Parameters

input T

The input model element

generatedType CodeTypeDeclaration

The generated type declaration

Returns

CodeTypeDeclaration

A new type declaration without members or null, if no interface shall be created.

GetName(T)

Gets the name of the class generated for the given model element

protected abstract string GetName(T input)

Parameters

input T

The input model element

Returns

string

The name of the class

RequireBaseClass(Func<T, T>)

Creates a dependency to generate the code for the base classes of the current class

public ITransformationRuleDependency RequireBaseClass(Func<T, T> selector)

Parameters

selector Func<T, T>

A function used to select the model element from which to generate a base class

Returns

ITransformationRuleDependency

The transformation rule dependency

RequireBaseClass<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration>, Func<T, TClass>)

Creates a dependency to generate the code for the base classes of the current class

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

Parameters

rule TransformationRuleBase<TClass, CodeTypeDeclaration>

The transformation rule that is used to generate the class

selector Func<T, TClass>

A function used to select the model element from which to generate a base class

Returns

ITransformationRuleDependency

The transformation rule dependency

Type Parameters

TClass

The model element type from which to generate the base class

RequireBaseClasses(Func<T, IEnumerable<T>>)

Creates a dependency to generate the code for the base classes of the current class

public ITransformationRuleDependency RequireBaseClasses(Func<T, IEnumerable<T>> selector)

Parameters

selector Func<T, IEnumerable<T>>

The function used to select the model elements from which to generate the base classes

Returns

ITransformationRuleDependency

The transformation rule dependency

RequireBaseClasses<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration>, Func<T, IEnumerable<TClass>>)

Creates a dependency to generate the code for the base classes of the current class

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

Parameters

rule TransformationRuleBase<TClass, CodeTypeDeclaration>

The transformation rule that is used to generate the base classes

selector Func<T, IEnumerable<TClass>>

The function used to select the model elements from which to generate the base classes

Returns

ITransformationRuleDependency

The transformation rule dependency

Type Parameters

TClass

The model element type from which to generate the base classes

RequireEvent<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent>, Func<T, TEvent>)

Creates a dependency to generate an event from a given subsequent model element

public ITransformationRuleDependency RequireEvent<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent> rule, Func<T, TEvent> selector) where TEvent : class

Parameters

rule TransformationRuleBase<TEvent, CodeMemberEvent>

The transformation rule that is used to generate the event

selector Func<T, TEvent>

The selector function that selects the model element from which to generate an event

Returns

ITransformationRuleDependency

The transformation rule dependency

Type Parameters

TEvent

The model element type from which to generate an event

RequireEvents<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent>, Func<T, IEnumerable<TEvent>>)

Creates a dependency to generate events from given subsequent model elements

public ITransformationRuleDependency RequireEvents<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent> rule, Func<T, IEnumerable<TEvent>> selector) where TEvent : class

Parameters

rule TransformationRuleBase<TEvent, CodeMemberEvent>

The transformation rule to generate events

selector Func<T, IEnumerable<TEvent>>

The selector function that selects the model elements from which to generate events

Returns

ITransformationRuleDependency

The transformation rule dependency

Type Parameters

TEvent

The model element type from which to generate events

RequireGenerateMethod<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod>, Func<T, TMeth>)

Cregates a dependency to generate a method from a given subsequent model element

public ITransformationRuleDependency RequireGenerateMethod<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod> rule, Func<T, TMeth> selector) where TMeth : class

Parameters

rule TransformationRuleBase<TMeth, CodeMemberMethod>

The method generator

selector Func<T, TMeth>

The selector function that selects the model element from which to generate the method

Returns

ITransformationRuleDependency

The transformation rule dependency

Type Parameters

TMeth

The model element type from which to generate a method

RequireGenerateMethods<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod>, Func<T, IEnumerable<TMeth>>)

Creates a dependency to generate methods from subsequent model elements

public ITransformationRuleDependency RequireGenerateMethods<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod> rule, Func<T, IEnumerable<TMeth>> selector) where TMeth : class

Parameters

rule TransformationRuleBase<TMeth, CodeMemberMethod>

The method generator

selector Func<T, IEnumerable<TMeth>>

The selector function that selects the model elements from which to generate the methods

Returns

ITransformationRuleDependency

The transformation rule dependency

Type Parameters

TMeth

The model elements type from which to generate methods

RequireGenerateProperties<TProp>(TransformationRuleBase<TProp, CodeMemberProperty>, Func<T, IEnumerable<TProp>>)

Creates a dependency to generate properties from subsequent model elements

public ITransformationRuleDependency RequireGenerateProperties<TProp>(TransformationRuleBase<TProp, CodeMemberProperty> rule, Func<T, IEnumerable<TProp>> selector) where TProp : class

Parameters

rule TransformationRuleBase<TProp, CodeMemberProperty>

The transformation rule for the property generation rule

selector Func<T, IEnumerable<TProp>>

The selector function to select the subsequent model elements

Returns

ITransformationRuleDependency

The created transformation rule dependency

Type Parameters

TProp

The model element type from which to generate a property

RequireGenerateProperty<TProp>(TransformationRuleBase<TProp, CodeMemberProperty>, Func<T, TProp>)

Creates a dependency to generate a property from a given subsequent model element

public ITransformationRuleDependency RequireGenerateProperty<TProp>(TransformationRuleBase<TProp, CodeMemberProperty> rule, Func<T, TProp> selector) where TProp : class

Parameters

rule TransformationRuleBase<TProp, CodeMemberProperty>

The property generator

selector Func<T, TProp>

The selector function that selects the model element from which to generate the property

Returns

ITransformationRuleDependency

The transformation rule dependency

Type Parameters

TProp

The model element type from which to generate a property

ResolveMultipleInheritanceMembers(CodeTypeDeclaration, HashSet<CodeTypeMember>, CodeConstructor)

Resolves the members inherited from multiple base classes

protected virtual void ResolveMultipleInheritanceMembers(CodeTypeDeclaration generatedType, HashSet<CodeTypeMember> shadows, CodeConstructor constructor)

Parameters

generatedType CodeTypeDeclaration

The generated type

shadows HashSet<CodeTypeMember>

The members that are shadowed by others

constructor CodeConstructor

The constructor to which initializations should be added

ShouldContainMembers(CodeTypeDeclaration, CodeTypeDeclaration)

Determines whether the provided type should contain members of the given base type

protected virtual bool ShouldContainMembers(CodeTypeDeclaration generatedType, CodeTypeDeclaration baseType)

Parameters

generatedType CodeTypeDeclaration

The type that is currently being generated

baseType CodeTypeDeclaration

The base types

Returns

bool

True if so, otherwise false

Transform(T, CodeTypeDeclaration, ITransformationContext)

Initializes the generated type declaration

public override void Transform(T input, CodeTypeDeclaration generatedType, ITransformationContext context)

Parameters

input T

The input model element

generatedType CodeTypeDeclaration

The generated class declaration

context ITransformationContext

The transformation context

Remarks

Can be overridden to refine code generation