Class ClassGenerator<T>
Represents a base class for a transformation rule that generates classes
Inheritance
Inherited Members
Namespace: NMF.CodeGen
Assembly: NMF.CodeGen.dll
Syntax
public abstract class ClassGenerator<T> : TransformationRule<T, CodeTypeDeclaration> where T : class
Type Parameters
Name | Description |
---|---|
T | The model element type from which the classes are generated |
Methods
| Edit this page View SourceAddImplementationBaseClass(CodeTypeDeclaration)
Modifies the given code declaration to respect that the generated class is the root of an inheritance tree
Declaration
protected virtual void AddImplementationBaseClass(CodeTypeDeclaration generatedType)
Parameters
Type | Name | Description |
---|---|---|
CodeTypeDeclaration | generatedType | The generated class declaration |
Remarks
This method can be overridden so that the derived transformation rule can inherit common base functionality
CreateInterfaceMembers(CodeTypeDeclaration, CodeTypeDeclaration)
Generates the interface members for the given type
Declaration
protected virtual void CreateInterfaceMembers(CodeTypeDeclaration generatedType, CodeTypeDeclaration interfaceDecl)
Parameters
Type | Name | Description |
---|---|---|
CodeTypeDeclaration | generatedType | The generated type |
CodeTypeDeclaration | interfaceDecl | The interface declaration |
CreateOutput(T, ITransformationContext)
Creates the output the transformation rule
Declaration
public override CodeTypeDeclaration CreateOutput(T input, ITransformationContext context)
Parameters
Type | Name | Description |
---|---|---|
T | input | The input model element |
ITransformationContext | context | The transformaton context |
Returns
Type | Description |
---|---|
CodeTypeDeclaration | A new code type declaration with set reference that references back to the code declaration |
Overrides
CreateSeparatePublicInterface(T, CodeTypeDeclaration)
Create a separate public interface for the given input
Declaration
protected virtual CodeTypeDeclaration CreateSeparatePublicInterface(T input, CodeTypeDeclaration generatedType)
Parameters
Type | Name | Description |
---|---|---|
T | input | The input model element |
CodeTypeDeclaration | generatedType | The generated type declaration |
Returns
Type | Description |
---|---|
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
Declaration
protected abstract string GetName(T input)
Parameters
Type | Name | Description |
---|---|---|
T | input | The input model element |
Returns
Type | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireBaseClass(Func<T, T> selector)
Parameters
Type | Name | Description |
---|---|---|
Func<T, T> | selector | A function used to select the model element from which to generate a base class |
Returns
Type | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireBaseClass<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration> rule, Func<T, TClass> selector) where TClass : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TClass, CodeTypeDeclaration> | rule | The transformation rule that is used to generate the class |
Func<T, TClass> | selector | A function used to select the model element from which to generate a base class |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The transformation rule dependency |
Type Parameters
Name | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireBaseClasses(Func<T, IEnumerable<T>> selector)
Parameters
Type | Name | Description |
---|---|---|
Func<T, IEnumerable<T>> | selector | The function used to select the model elements from which to generate the base classes |
Returns
Type | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireBaseClasses<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration> rule, Func<T, IEnumerable<TClass>> selector) where TClass : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TClass, CodeTypeDeclaration> | rule | The transformation rule that is used to generate the base classes |
Func<T, IEnumerable<TClass>> | selector | The function used to select the model elements from which to generate the base classes |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The transformation rule dependency |
Type Parameters
Name | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireEvent<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent> rule, Func<T, TEvent> selector) where TEvent : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TEvent, CodeMemberEvent> | rule | The transformation rule that is used to generate the event |
Func<T, TEvent> | selector | The selector function that selects the model element from which to generate an event |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The transformation rule dependency |
Type Parameters
Name | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireEvents<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent> rule, Func<T, IEnumerable<TEvent>> selector) where TEvent : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TEvent, CodeMemberEvent> | rule | The transformation rule to generate events |
Func<T, IEnumerable<TEvent>> | selector | The selector function that selects the model elements from which to generate events |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The transformation rule dependency |
Type Parameters
Name | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireGenerateMethod<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod> rule, Func<T, TMeth> selector) where TMeth : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TMeth, CodeMemberMethod> | rule | The method generator |
Func<T, TMeth> | selector | The selector function that selects the model element from which to generate the method |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The transformation rule dependency |
Type Parameters
Name | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireGenerateMethods<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod> rule, Func<T, IEnumerable<TMeth>> selector) where TMeth : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TMeth, CodeMemberMethod> | rule | The method generator |
Func<T, IEnumerable<TMeth>> | selector | The selector function that selects the model elements from which to generate the methods |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The transformation rule dependency |
Type Parameters
Name | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireGenerateProperties<TProp>(TransformationRuleBase<TProp, CodeMemberProperty> rule, Func<T, IEnumerable<TProp>> selector) where TProp : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TProp, CodeMemberProperty> | rule | The transformation rule for the property generation rule |
Func<T, IEnumerable<TProp>> | selector | The selector function to select the subsequent model elements |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The created transformation rule dependency |
Type Parameters
Name | Description |
---|---|
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
Declaration
public ITransformationRuleDependency RequireGenerateProperty<TProp>(TransformationRuleBase<TProp, CodeMemberProperty> rule, Func<T, TProp> selector) where TProp : class
Parameters
Type | Name | Description |
---|---|---|
TransformationRuleBase<TProp, CodeMemberProperty> | rule | The property generator |
Func<T, TProp> | selector | The selector function that selects the model element from which to generate the property |
Returns
Type | Description |
---|---|
ITransformationRuleDependency | The transformation rule dependency |
Type Parameters
Name | Description |
---|---|
TProp | The model element type from which to generate a property |
ResolveMultipleInheritanceMembers(CodeTypeDeclaration, HashSet<CodeTypeMember>, CodeConstructor)
Resolves the members inherited from multiple base classes
Declaration
protected virtual void ResolveMultipleInheritanceMembers(CodeTypeDeclaration generatedType, HashSet<CodeTypeMember> shadows, CodeConstructor constructor)
Parameters
Type | Name | Description |
---|---|---|
CodeTypeDeclaration | generatedType | The generated type |
HashSet<CodeTypeMember> | shadows | The members that are shadowed by others |
CodeConstructor | constructor | The constructor to which initializations should be added |
ShouldContainMembers(CodeTypeDeclaration, CodeTypeDeclaration)
Determines whether the provided type should contain members of the given base type
Declaration
protected virtual bool ShouldContainMembers(CodeTypeDeclaration generatedType, CodeTypeDeclaration baseType)
Parameters
Type | Name | Description |
---|---|---|
CodeTypeDeclaration | generatedType | The type that is currently being generated |
CodeTypeDeclaration | baseType | The base types |
Returns
Type | Description |
---|---|
bool | True if so, otherwise false |
Transform(T, CodeTypeDeclaration, ITransformationContext)
Initializes the generated type declaration
Declaration
public override void Transform(T input, CodeTypeDeclaration generatedType, ITransformationContext context)
Parameters
Type | Name | Description |
---|---|---|
T | input | The input model element |
CodeTypeDeclaration | generatedType | The generated class declaration |
ITransformationContext | context | The transformation context |
Overrides
Remarks
Can be overridden to refine code generation